1

I use AngularFire & Cloud Firestore in my project and I need to make a query with multiple conditions(where) to a collection.

I tried to use this code but it's ignoring the second condition.

 this.itemCollection = this.afs.collection<Item>('items', ref => {

 return ref
         .where('size', '==', 'large')
         .where('brand', '==', 'some-brand')
 })
 this.items = this.itemCollection.valueChanges();

What am I doing wrong, how do I apply multiple conditions in AngularFire?

Angry Beaver
  • 415
  • 1
  • 6
  • 18

2 Answers2

2

Your code needs to be:

this.itemCollection = this.afs.collection<Item>('items', ref => ref.where('size', '==', 
'large').where('brand', '==', 'some-brand'))
return this.items = this.itemCollection.valueChanges();
0

Queries on different fields using multiple where clauses are invalid [1][2]. This is not true => multiple where queries are supported by firebase when the query type is the same, eg "==" && "==". 3 only where you mix types eg "==" && "=>" will firebase reject it.

However, check this response to another questions on SO: Query based on multiple where clauses in Firebase.

Ayman Nedjmeddine
  • 11,521
  • 1
  • 20
  • 31