Search code examples
angularfirebaseangularfire2

¿how to execute an angularfire query with 2 "where" clauses in angular fire?


I'm trying to execute a query with two "where" clauses in the same field, using AngularFire. The query works when I set only one "where", but retrieves no results when using two clauses. The same query works normally when using firebase (not angular fire)

  query2(callback){
    this.resultingArray = [];

    let query =this.angularFirestore.firestore.collection("myCollection")

    //Doesn't work with two clauses:
    .where("date",">=",this.startDate).where("date","<=",this.endDate)

    //works with only one clause:
    //.where("date",">=",this.startDateISO)

    query.get().then((querySnapshot)=>{
      querySnapshot.forEach((docs) => {
        this.resultingArray.push(docs)
      })
     })
    .then(()=>{
          callback()
        }).catch((err)=>{
          console.log(err)
        })
     }

Solution

  • Try this.

    let query =this.angularFirestore.firestore.collection("myCollection", ref => {
      return ref.where("date",">=",this.startDate).where("date","<=",this.endDate);
    });