Google Firestore - 如何在一次往返中通过多个 ID 获取多个文档?

新手上路,请多包涵

我想知道是否有可能在到 Firestore 数据库的一次往返(网络调用)中通过 ID 列表获取多个文档。

原文由 Joon 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 311
2 个回答

如果你在节点内:

https://github.com/googleapis/nodejs-firestore/blob/master/dev/src/index.ts#L978

 /**
* Retrieves multiple documents from Firestore.
*
* @param {...DocumentReference} documents - The document references
* to receive.
* @returns {Promise<Array.<DocumentSnapshot>>} A Promise that
* contains an array with the resulting document snapshots.
*
* @example
* let documentRef1 = firestore.doc('col/doc1');
* let documentRef2 = firestore.doc('col/doc2');
*
* firestore.getAll(documentRef1, documentRef2).then(docs => {
*   console.log(`First document: ${JSON.stringify(docs[0])}`);
*   console.log(`Second document: ${JSON.stringify(docs[1])}`);
* });
*/

这是专门针对服务器SDK的

更新: Cloud Firestore 现在支持 IN 查询!

 myCollection.where(firestore.FieldPath.documentId(), 'in', ["123","456","789"])

原文由 Nick Franceschina 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题