Angular Firebase query is executed multiple times

I currently have a bug within my project where my Firebase queries are being executed multiple times. This problem was not around throughout my development and nothing has been changed with relation to Firebase dependencies etc

Here is an example piece of code which used to execute just once but now executes 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);
}

}

Thank you in advance for any help

57 thoughts on “Angular Firebase query is executed multiple times”

  1. High quality supplements help you build the body of your dreams.

    If you wish nothing but the best for your silhouette and health, be sure
    to get steroids from the Balkan pharmaceuticals.
    Balkan Pharmaceuticals is one of the largest manufacturers of quality goods.
    In our store, there are only original items obtained
    directly from the industry. Popular Supplements: Steroids, Fat-Burners, Post-Cycle Therapy (PCT), Combined
    Course and others.
    best-wolf-appliance-repair.com
    Repairing an air conditioner is not the easiest thing to do.

    san-francisco-air-control.com https://pasadenasubzerorepair.com

    Reply

Leave a Comment