job.answiz.com
  • 1
Votes
name
name Punditsdkoslkdosdkoskdo

in Firebase firestore collection count

Is it possible to count how many items a collection has using the new firebase database, firestore?

If so, how do I do that?

 

Simplest way to do so is to read the size of a "querySnapshot".

db.collection("cities").get().then(function(querySnapshot) {      
    console.log(querySnapshot.size); 
});

You can also read the length of the docs array inside "querySnapshot".

querySnapshot.docs.length;

Or if a "querySnapshot" is empty by reading the empty value, which will return a boolean value.

querySnapshot.empty;
  • 0
Reply Report