Reputation: 6900
I have a collection foo
of 1000 documents where each document has a field bar
, a number. If I do a query db.collection('foo').orderBy("bar", "desc").limit(5)
how many reads will I be charged for?
Upvotes: 1
Views: 508
Reputation: 600130
There is no additional charge for using an orderBy
statement in your query, as the ordering of the results can be determined from the indexes. So Firestore doesn't have to read all documents in the collection to determine the value of bar
in your scenario, it just needs to read the index for bar
.
In fact, Firestore never needs to read all documents to satisfy a query. It's whole performance guarantee is based on being able to execute any query it allows by reading slices from indexes only.
You'll be charged for at least 1 and at most 5 reads by that query. The exact charge depends on how you implement the read operation, and the state of the local cache.
Things to keep in mind:
Upvotes: 3
Reputation: 50930
5 reads. You get charged for what you request which in this case is 5 due to limit(5)
irrespective of amount of documents you have.
Read more at: Understand Cloud Firestore Billing
Upvotes: 0