Collection Snapshot Elements Map in Firebase Firestore

Firebase Firestore Guides shows how to iterate documents in a collection snapshot using forEach :

 db.collection("cities").get().then(function(querySnapshot) { querySnapshot.forEach(function(doc) { console.log(doc.id, " => ", doc.data()); }); }); 

I assumed that it will support map , but it is not. How to display a snapshot?

+5
source share
1 answer

Answer:

 querySnapshot.docs.map(function(doc) { # do something }) 

The link to the Firestore page shows the docs property in the snapshot.

docs non-null Array of non-zero firebase.firestore.DocumentSnapshot

An array of all documents in QuerySnapshot.

+8
source

Source: https://habr.com/ru/post/1272411/


All Articles