Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * 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])}`);
- * });
- */
- function getById (path, id) {
- return firestore.getAll(
- [].concat(ids).map(id => firestore.doc(`${path}/${id}`)
- )
- }
- getById('collection', 'some_id')
- getById('collection', ['some_id', 'some_other_id'])
- 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()))
- }
- 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())))
- }
Add Comment
Please, Sign In to add comment