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

标签 javascript node.js firebase google-cloud-platform google-cloud-firestore

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

最佳答案

如果您在 Node 中:

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 Now Supports IN Queries!

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

关于javascript - Google Firestore - 如何在一次往返中通过多个 ID 获取多个文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55785899/

相关文章:

javascript - 使用 jQuery 检测 DIV 中是否存在滚动条?

node.js - 在计算引擎托管的nodeJS项目中的哪里定义datastore-indexes.xml?

javascript - 以对象数组形式检索数据 ||火力基地

javascript - angularjs中的编译和链接函数有什么区别

javascript - .hover 和 div 出现干扰

javascript - 替换符合条件的括号

javascript - 在 Node.js 中编写可重新调度的 cron 作业

node.js - 如何使用passport.js正确实现serializeUser?

ios - GeoFire 给 CocoaPods 带来问题

swift - 使用 caseInSensitive 在 Firebase 中保存和/或查询用户显示名称?