Google Firestore-如何在一次往返中通过多个ID获取文档? [英] Google Firestore - how to get document by multiple ids in one round trip?
本文介绍了Google Firestore-如何在一次往返中通过多个ID获取文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否有可能在一次往返(网络呼叫)到Firestore的ID列表中获取多个文档.
I am wondering if it's possible to get multiple documents by list of ids in one round trip (network call) to the Firestore.
推荐答案
(如果您位于Node中):
if you're within Node:
https://github.com/googleapis/nodejs-firestore/blob/master/dev/src/index.ts#L701
/**
* 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 [客户端sdk]现在支持IN查询!"
UPDATE: "Cloud Firestore [client-side sdk] Now Supports IN Queries!"
https://firebase.googleblog. com/2019/11/cloud-firestore-now-supports-in-queries.html
myCollection.where(firestore.FieldPath.documentId(), 'in', ["123","456","789"])
这篇关于Google Firestore-如何在一次往返中通过多个ID获取文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文