0

I am trying to do a query with an OR operator. If written in SQL would be kinda like:

SELECT * FROM object WHERE last_queried < Now() OR last_queried == null

This is the actual query:

firestore.collection('sources').where('last_queried', '<', oneHourAgo).where('last_queried', '==', null).where('enabled', '==', true).where('uid', '==', uid).get()

Any idea how to handle a null or a specific value?

Tyler C
  • 531
  • 1
  • 5
  • 12
  • Firestore does not support logical or queries that can satisfy this. You would need to perform two queries and merge the results on the client. – Doug Stevenson Mar 30 '20 at 01:40
  • What a shame. I feel like something like this should have been easy to implement on their end. – Tyler C Mar 30 '20 at 02:14
  • It would have been implemented by two queries, the same way your client code would have to do it. But this is one of the limitations that allows for Firestore to scale massively. Your job is to model your data in a way that works with the way it indexes documents. This often involves creating a new field that represents the precomputation of the logical OR's conditions, and use that field for your query. – Doug Stevenson Mar 30 '20 at 02:52

0 Answers0