const sub1 = this.angularFirestore.collection('Date').doc('username).collection('time').snapshotChanges();
const sub2 = await sub1.subscribe((snapData: DocumentChangeAction<any>[]) => {
`
// After each minute, new data is inserted in firebase storage, and the below
// code runs automatically, because I have subscribed to it.
// now the problem is, after 1 minute, snapData has duplicate records
// and for loop is also executed.
// method for getting URL from firebase storage, called from below for loop`
const send = storageRef =>
new Promise(resolve => {
storageRef.getDownloadURL().then(url => {
resolve(url);
}, err => {
}
);
}
);
for (const d of snapData) {
const storageRef =
firebase.storage().ref().child(d.payload.doc.data().timeEachMinute);
const ImgUrl = await send(storageRef);
this.timestampsList.push({
dateObj: d.payload.doc.data().dateObj,
imageUrl: ImgUrl,
date: d.payload.doc.data().screenShot,
name: d.payload.doc.data().user
});
}
}
sub2.unsubscribe();
For example, I am retrieving 1000 records, which may not be completed in one minute, suppose 500 records are retrieved, after one minute, new records start fetching from start as well as 501 onward, which lead to duplicate records. Now i am confused whether the problem is in for loop or observer subscription.