Guest User

Untitled

a guest
Jan 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. /**
  2. * Retrieves multiple documents from Firestore.
  3. *
  4. * @param {...DocumentReference} documents - The document references
  5. * to receive.
  6. * @returns {Promise<Array.<DocumentSnapshot>>} A Promise that
  7. * contains an array with the resulting document snapshots.
  8. *
  9. * @example
  10. * let documentRef1 = firestore.doc('col/doc1');
  11. * let documentRef2 = firestore.doc('col/doc2');
  12. *
  13. * firestore.getAll(documentRef1, documentRef2).then(docs => {
  14. * console.log(`First document: ${JSON.stringify(docs[0])}`);
  15. * console.log(`Second document: ${JSON.stringify(docs[1])}`);
  16. * });
  17. */
  18.  
  19. function getById (path, id) {
  20. return firestore.getAll(
  21. [].concat(ids).map(id => firestore.doc(`${path}/${id}`)
  22. )
  23. }
  24.  
  25. getById('collection', 'some_id')
  26.  
  27. getById('collection', ['some_id', 'some_other_id'])
  28.  
  29. async getUsers({userIds}) {
  30. const refs = userIds.map(id => this.firestore.doc(`users/${id}`))
  31. const users = await this.firestore.getAll(...refs)
  32. console.log(users.map(doc => doc.data()))
  33. }
  34.  
  35. getUsers({userIds}) {
  36. const refs = userIds.map(id => this.firestore.doc(`users/${id}`))
  37. this.firestore.getAll(...refs).then(users => console.log(users.map(doc => doc.data())))
  38. }
Add Comment
Please, Sign In to add comment