I'm currently facing an issue in my project where Firebase queries are being executed multiple times. This problem wasn't present during development and no changes have been made to the Firebase dependencies.
Below is a snippet of code that used to run once but now runs multiple times:
ngOnInit(): void {
this.array = [];
// Try-Catch function reading data from Firestore
try {
this.db.collection("myCollection").where("Age", "==", "20").onSnapshot(snapshot => {
snapshot.docs.forEach (() => {
this.db.collection('Jobs').get().then (snapshot2 => {
snapshot2.docs.forEach (snapshot3 => {
if (snapshot3.id.includes('Unemployed')){
this.array.push(
{
ID: snapshot3.id
}
);
}
})
})
})
})
} catch (error) {
console.log(error.message);
}
}
Any assistance on resolving this issue would be greatly appreciated. Thank you!