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?
As far as I know there is no build-in solution for this and it is only possible in the node sdk right now. If you have a
db.collection('someCollection')
you can use
.select([fields])
to define which field you want to select. If you do an empty select() you will just get an array of document references.
example:
db.collection('someCollection').select().get().then(
(snapshot) => console.log(snapshot.docs.length)
);
This solution is only a optimization for the worst case of downloading all documents and does not scale on large collections!
Also have a look at this:
How to get a count of number of documents in a collection with Cloud Firestore