简体   繁体   English

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

[英]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.

相关问题 如何在 Android 上使用 whereArrayContains() 过滤器查询包含 Firestore 集合中对象数组的文档? - How to query documents containing array of objects in Firestore collection using whereArrayContains() filter on Android? 尝试使用用户配置文件中的数组一次从 React 中的 Firestore 查询多个文档 - Trying to query multiple documents from Firestore in React at once, using an array from the users profile Firestore 查询文档以字符串开头 - Firestore query documents startsWith a string 如何列出 Flutter Firestore 中文档的值? - How to list values ​from documents in Flutter Firestore? 如何在 Cloud Firestore 查询中加入多个文档? - How to join multiple documents in a Cloud Firestore query? Firestore 查询文档以特定字符开头 - Firestore query documents startsWith a specific character Firestore 查询多个父文档的所有子集合 - Firestore query all subcollections of multiple parent documents Node JS / Firebase Admin SDK / Firestore - 使用快照接收 firebase 文档后获取空数组 - Node JS / Firebase Admin SDK / Firestore - Getting empty array after receiving firebase documents using snapshots 如何在 Firestore 的子集合中查询文档? - How to Query for documents in a sub collection in Firestore? 从 Firestore 集合中获取包含所有文档的列表 - Get a list with all documents from a Firestore collection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM