Reputation: 435
I have a question about Reads/Write in a Firestore DB. The scenario is:
I have a Collection "City" (for example 20 Cities) and it has a subcollection "Restaurants" (e.g 500 restaurants):
Now is my question: When I want to get all Restaurant in a City, how many reads would Firestore bill? 500?
And when I want to add a Restaurant: Would it only need 1 write to add this document to the subcollection?
Upvotes: 2
Views: 149
Reputation: 598718
As Andres said: you are charged for document reads and writes. It doesn't matter what collection or subcollection the document comes from, each time the server reads a document on your behalf, you're charged for that document read.
So if you read 500 restaurant documents out of the subcollection of a city, you'll be charged for 500 document reads. If you add a single document to that subcollection, you're charged for a single document write.
If you regularly find yourself reading the same set of documents (e.g. the same 500 restaurants for all users in that city), consider creating a data model that reduces the number of documents you need to read. For example: you'll probably need a subset of the information from each restaurant, so you could extract that for all restaurants in the city into a "top restaurants list" document. This type of data duplication is quite normal in NoSQL databases, and key to keeping great performance with a reasonable cost.
Also see:
Upvotes: 3
Reputation: 3744
One document read/write always costs the same, it could be in a collection, or a subcollection, or a subcollection of a subcollection - or a sub of sub of sub... you got the idea :)
Upvotes: 1