小编典典

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

all

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


阅读 158

收藏
2022-08-29

共1个答案

小编典典

如果您在节点内:

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 [client-side sdk] 现在支持 IN 查询!”

https://firebase.googleblog.com/2019/11/cloud-firestore-now-supports-in-
queries.html

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

2022-08-29