2

Hello Firestore lovers !

I am trying to retrieve all documents that do not have a field set. Here my field is named "source".

  • I can get the documents where "source" is equal "".
  • I can also get the documents where "source" is null.
  • But I can't find the way to get documents where source is not set at all in the document.

Sample python 3 working code using the google cloud python library :

from google.cloud import firestore

product_ref = "product"
db = firestore.Client()
doc_ref = db.collection(product_ref)

docs = doc_ref.where(u'source', u'==', None).get()

This works and returns all the document with source == null.

I have found very few lines on github on a IS_NAN operator but I have not been able to use it to get the documents where "source" field is missing.

Thank you !

Juan Lara
  • 6,454
  • 1
  • 22
  • 31
  • 1
    There is no operator to check for inequality on the back-end: https://stackoverflow.com/questions/47251919/firestore-how-to-perform-a-query-with-inequality-not-equals. The closest you can get is checking for non-existence of the field: https://twitter.com/abeisgreat/status/929808518428762112 – Frank van Puffelen Nov 28 '17 at 14:35
  • Thank you for the link. It was an "==" so I had hope it work. The trick from @abeisgreat on Twitter is great but I am not sure it will save me on this. I will have to loop over all documents once. Thanks again =) – Gianluca Ricciardelli Nov 28 '17 at 17:00
  • The link to the twitter post is gone. Is there anywhere else I can find that? It is exactly what I need (check for non-existence of a field). – Love to Code Dec 30 '20 at 11:23

0 Answers0