Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Firebase Firestore: Query and get documents that contain the queried value in one of the fields

Is it possible to query a collection and return documents that contain the queried value in one of the fields, regardless of which field it is?

For example, a typical query would go like this:

db.collection('collection').where('id','==',targetvalue).get()

Let’s assume a hypothetical scenario where any field in the documents under the collection can contain the target value. Is it possible to query for such documents? If so, how can I do it?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Is it possible to query a collection and return documents that contain the queried value in one of the fields, regardless of which field it is?

No, you cannot do that unless you create a different separate query for each field:

db.collection('collection').where('id','==',targetvalue).get()
db.collection('collection').where('otherField','==',targetvalue).get()
//And so on.

You cannot search for a value in all fields in a document. If you’re thinking of using wildcards, please note that is not possible in Firestore.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading