Collections don't know how many documents they contain so to get the count you have to retrieve all of the documents to then get a count. That could be time consuming as well as a lot of reading (cost).
The simple solution is to keep the count in another collection or at a known document location within the collection.
Generically speaking, suppose we have three collections, Courses, Users and Locations and each one could have 0 to thousands of documents.
Users
user_0
...some fields
user_1
...some fields
Courses
course_0
...some fields
course_1
...some fields
Locations
location_0
...some fields
location_1
...some fields
As previously mentioned, if there are a limited number of documents simply reading Users (for example) and getting the count of the documents from the snapshot works and is simple. However, as Users grows so does the document count and cost.
The better and scalable solution is to keep anther collection of counts
Document_Counts
users_collection
count: 2
courses_collection
count: 2
locations_collection
count: 2
Then when you want the number of users, simply read the Document_Counts/users_collection
document and get the count from the count
field.
Firestore has a lighting fast and simple increment and decrement function so as a document is added to Users, for example, increment that same count field.