Google Firestore - 1 回のラウンドトリップで複数の ID で複数のドキュメントを取得するにはどうすればよいでしょうか? 質問する

Google Firestore - 1 回のラウンドトリップで複数の ID で複数のドキュメントを取得するにはどうすればよいでしょうか? 質問する

Firestore データベースへの 1 回のラウンドトリップ (ネットワーク呼び出し) で、ID のリストによって複数のドキュメントを取得できるかどうか疑問に思っています。

ベストアンサー1

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 が IN クエリをサポートするようになりました。

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

おすすめ記事