Small collection (less than 100 documents)
db.collection('...').get().then(snap => {
size = snap.size // will return the collection size
});
Large Collection
You can maintain special collection to store number of users in your users
collection. Whenever you need to read the count of users, you can call this special collection which keeps count of users. By doing this, you can save lot of Read operations.
When new user register into your system, you can increment the value of this special collection using
FieldValue.increment()
Firestore now allows incrementing counters, completely atomically, and without reading the data prior. This ensures we have correct counter values even when updating from multiple sources simultaneously (previously solved using transactions), while also reducing the number of database reads we perform.
- Special Collection is new collection just used for maintaining users count and store document id of each users
Server SDK (Admin SDK)
db.collection('foo').select()
the server will send you the documents that match, but will omit all fields from the query result.