'Query a list of documents in firestore using an array
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.
Solution 1:[1]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Frank van Puffelen |
