Google Firestore - how to get document by multiple ids in one round trip?

前端 未结 11 1803
余生分开走
余生分开走 2020-11-21 22:49

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

11条回答
  •  [愿得一人]
    2020-11-21 23:36

    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>} 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])}`);
    * });
    */
    

    This is specifically for the server SDK

    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"])

提交回复
热议问题