[英]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?是否可以使用 ID 数组查询 firestore 中的文档列表?
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.尽管存在具有给定 ID 的文档,但 selectedUsers.data() 未定义。 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.您可以使用in
运算符和FieldPath.documentId()
function 来构建一个查询,该查询最多可以按 ID 获取 10 个文档。
Something like:就像是:
firestore().collection('Users')
.where(FieldPath.documentId(), 'in', UserIDs)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.