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

后端 未结 9 1986
没有蜡笔的小新
没有蜡笔的小新 2020-11-22 02:07

From the docs:

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

How can I perform an <

9条回答
  •  佛祖请我去吃肉
    2020-11-22 02:36

    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.

提交回复
热议问题