Home > Software design >  How to perform a query in Firestore string field to match against multiple values?
How to perform a query in Firestore string field to match against multiple values?

Time:09-23

I have a collection in Firestore that has a field status which is either "COMPLETE" "INCOMPLETE" or "ON HOLD"

How would I perform a query that only returns the documents matching "COMPLETE" and "INCOMPLETE"?

  FirebaseFirestore.instance.collection('tasks')
    .where('status', isEqualTo: 'COMPLETE')
    .where('status', isEqualTo: 'INCOMPLETE');

CodePudding user response:

You are looking for whereIn operator which will fetch documents where the provided field (in this case status) has either of the values provided in the array/list passed:

FirebaseFirestore.instance.collection('tasks').where('status', whereIn: ['COMPLETE','INCOMPLETE']);
  • Related