Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform compound queries with logical OR in Cloud Firestore?

From the docs:

You can also chain multiple where() methods to create more specific queries (logical AND).

How can I perform an OR query? Example:

  1. Give me all documents where the field status is open OR upcoming
  2. Give me all documents where the field status == open OR createdAt <= <somedatetime>
like image 533
ProblemsOfSumit Avatar asked Oct 08 '17 14:10

ProblemsOfSumit


People also ask

Can firestore update multiple documents matching a condition using one query?

Cloud Firestore does not support the equivalent of SQL's update queries.


1 Answers

OR isn't supported as it's hard for the server to scale it (requires keeping state to dedup). The work around is to issue 2 queries, one for each condition, and dedup on the client.


Edit (Nov 2019):

Cloud Firestore now supports IN queries which are a limited type of OR query.

For the example above you could do:

// Get all documents in 'foo' where status is open or upcmoming db.collection('foo').where('status','in',['open','upcoming']).get() 

However it's still not possible to do a general OR condition involving multiple fields.

like image 165
Dan McGrath Avatar answered Oct 03 '22 22:10

Dan McGrath