I'm trying to save data in firebase. I have an array from that I want to save data in firebase. When the size of the array is small it works but when the size is greater than 50 it is stuck and not responding to anything.
I have tried something like this
async handleOkCpy() {
const modelId = this.cpyRadioValue;
const mdlStgCopied = [];
this.isCopying = true;
let subscription;
subscription = this.rcService.getSettingGroupData(this.cpyRadioValue).subscribe(
async res => {
const newAddedSetting = [];
res.map(setting => {
const index = this.settingGrpdata.findIndex(id => setting.id === id.id);
if (index === -1) {
newAddedSetting.push(setting);
}
});
console.log('Get data');
await Promise.all(
newAddedSetting.map(async s => {
console.log('Start');
await this.rcService.copySetting(this.settingId, s.id, s.typeId, s.data);
console.log('Done');
})
);
console.log('here done');
// await this.copyModelDiagram(modelId);
this.nzMessageService.success('Settings has been copied successfully!');
this.isCopying = false;
// Unsubscribe observable to prevent infinite loopings
subscription.unsubscribe();
},
err => {
this.nzMessageService.error(err);
}
);
this.isVisibleCpySett = false;
this.cpyRadioValue = '';
}
Myservice
// copySetting
copySetting(modelId, settGrpDocId, settingTypeId, settingData) {
const serverTimeStamp = firebase.firestore.FieldValue.serverTimestamp();
const data = {
typeId: settingTypeId,
data: settingData,
updatedAt: serverTimeStamp,
settingId: settGrpDocId
};
return this.afs
.collection(`env/${currentENV.env}/baseModels`)
.doc(modelId)
.collection('settingsGroup')
.doc(settGrpDocId)
.set(data);
}
According to the code, the start message is equal to done, but I'm getting different "done" each time I call my function.
I don't know what happens here.