Implementing OR in firestore query - Firebase firestore

Edit (November 2019) Cloud Firestore now supports "IN" queries (announcement) which allows you to do a type of OR queries that look for documents with one of a few values on the same field.

For example for the query above:

db.collection('users')
  .where('company_id', '==', companyId)
  .where('role', 'in', ['Maker', 'Checker', 'Approver']);

Original answer

There is no "OR" query in Cloud Firestore. If you want to achieve this in a single query you will need a single field like maker_or_checker_or_approver: true.

Of course you can always do three queries and join them on the client.


This is now being made possible in Firestore by newly-added support for both the in and array-contains-any operators, which allow querying for up to 10 values in a single query.

https://firebase.googleblog.com/2019/11/cloud-firestore-now-supports-in-queries.html

So, using your example, the query would look something like this.

db.collection('users')
    .where('company_id', '==', companyId)
    .where('role', 'in', ['Maker', 'Checker', 'Approver']);

In the above example substitute in for array-contains-any if your data is stored in an array.