Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore get documents where value not in array?

Is there a way to get all documents which array field does not contain one or more values, now there is "array-contains" but is there something like "array-not-contains"?

like image 461
astro Avatar asked Aug 29 '18 20:08

astro


People also ask

How do I get specific data from firestore?

There are two ways to retrieve data stored in Cloud Firestore. Either of these methods can be used with documents, collections of documents, or the results of queries: Call a method to get the data. Set a listener to receive data-change events.

What is query snapshot?

A QuerySnapshot contains zero or more DocumentSnapshot objects representing the results of a query. The documents can be accessed as an array via the docs property or enumerated using the forEach method. The number of documents can be determined via the empty and size properties.


2 Answers

You can only query Firestore based on indexes, so that queries all scale up to search billions of documents without performance problems.

Indexes work by recording values that exist in your data set. An index can't possibly be efficient if it tracks things that don't exist. This is because the universe of non-existant values compared to your data set is extremely large and can't be indexed as such. Querying for non-existence of some value would require a scan of all your documents, and that doesn't scale.

like image 84
Doug Stevenson Avatar answered Oct 23 '22 13:10

Doug Stevenson


I don't think that is possible at the moment. I would try looking at this blog post for reference.

better arrays in cloud firestore

You might need to convert your array to an object so that you can query by (property === false)Convert array to object

like image 5
chris Avatar answered Oct 23 '22 12:10

chris