繁体   English   中英

使用数组查询 firestore 中的文档列表

[英]Query a list of documents in firestore using an array

是否可以使用 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();

尽管存在具有给定 ID 的文档,但 selectedUsers.data() 未定义。 我知道我可以执行循环,我只是想知道我尝试的方式是否可行。

您可以使用in运算符FieldPath.documentId() function 来构建一个查询,该查询最多可以按 ID 获取 10 个文档。

就像是:

firestore().collection('Users')
  .where(FieldPath.documentId(), 'in', UserIDs)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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