Google Firestore - 如何在一次往返中通过多个 ID 获取多个文档? [英] Google Firestore - How to get several documents by multiple ids in one round-trip?

查看:18
本文介绍了Google Firestore - 如何在一次往返中通过多个 ID 获取多个文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am wondering if it's possible to get multiple documents by a list of ids in one round trip (network call) to the Firestore database.

推荐答案

如果你在 Node 中:

if you're within 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 [客户端 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆