Rumah > Soal Jawab > teks badan
P粉6330757252023-08-28 12:45:41
Sebenarnya, anda akan menggunakan firestore.getAll seperti ini
async getUsers({userIds}) { const refs = userIds.map(id => this.firestore.doc(`users/${id}`)) const users = await this.firestore.getAll(...refs) console.log(users.map(doc => doc.data())) }
Atau gunakan sintaks Promise
getUsers({userIds}) { const refs = userIds.map(id => this.firestore.doc(`users/${id}`)) this.firestore.getAll(...refs).then(users => console.log(users.map(doc => doc.data()))) }
P粉8603709212023-08-28 12:42:52
Jika anda berada dalam 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])}`); * }); */
Ini khusus untuk pelayan SDK
Kemas kini: Cloud Firestore kini menyokong pertanyaan IN!
myCollection.where(firestore.FieldPath.documentId(), 'in', ["123","456","789"])