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

Time:04-12

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?

CodePudding user response:

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.

  • Related