Is it possible to count how many items a collection has using the new Firebase database, Cloud 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;
db.collection('someCollection')
.select([fields])
db.collection('someCollection').select().get().then( (snapshot) => console.log(snapshot.docs.length) );