简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM