theJuls
theJuls

Reputation: 7460

Getting Firebase document with falsy values

I would like to fetch an entry from my collection that either contains a value of an item set to false or the value is simply not set at all. Is this possible through a firebase query?

So for example, this would be the query to get the value set to false:

return db
    .collection('myCollection')
    .where('someAttribute', '==', false)

But what if I also want to fetch the items where someAttribute is not set at all?

Upvotes: 3

Views: 207

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317497

It's currently not possible to check if some field is not present in a document. The way Firestore indexes work is by checking known values against actual values in documents. Missing values are not indexed.

You might want to consider pre-populating new documents with known existing values. You could enforce this from the client with security rules, or by populating values after addition with Cloud Functions triggers.

Upvotes: 3

Related Questions