Home > OS >  How to get records in Andorid (kotlin) where field does not exist in all documents in Firestore?
How to get records in Andorid (kotlin) where field does not exist in all documents in Firestore?

Time:10-22

I want filter for one field that does not exist in all records in my document in firestore.

I'm using Android Kotlin with 'com.google.firebase:firebase-firestore-ktx:23.0.3'

CodePudding user response:

you can use .orderBy() function,
From documentation

An orderBy() clause also filters for existence of the given field. The result set will not include documents that do not contain the given field.

CodePudding user response:

Firestore queries only return documents that are present in the index(es) that are used for that query. Documents that don't have a certain field are not present in the index on that field, so can never be returned by queries on that field.

This means there is no way to use a query to do what you want. You'll need to read all documents from the collection and check in your application code whether the field is present.

  • Related