简体   繁体   中英

Is it possible to fetch only a single document based on a field in Cloud-Firestore?

is there a possibility to fetch a document based on a field? For example, if I have a collection called users that contains documents such as "usrID1", "usrID2", ... and each has a field inside called "city", now, can I search the entire collection and fetch ONLY the ones that has the field "city" equal to "New York"?

I know if I do it this way firebase.firestore().collection('users').get() and then extract only the needed data like .... doc.data().city but this would cost me a lot as each user is fetching the entire collection whenever they query that, moreover, its risky as each user will have the data of all other users.

您可以使用 firebase.firestore().collection('users').where("city", isEqualTo: "New York").get()

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