Is is possible to query a list of documents in firestore using an array of IDs?
const UserIDs = ['zHYYvrVPLA9LOV6edwOrQhQLt6k1', 'JhUvvrNbfD9LOV6edwOrQhQLt8Gf'
'] //each ID in the array is an existent document id in the collection Users
const selectedUsers = await firestore().collection('Users').doc(UserIDs).get();
selectedUsers.data() is undefined despite that the documents with the given IDs exists. I know I can perform a loop, I was just wondering if the way I tried is possible.
You can use the in
operator and the FieldPath.documentId()
function to build a query that can get up to 10 documents by their ID.
Something like:
firestore().collection('Users')
.where(FieldPath.documentId(), 'in', UserIDs)
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.