Reputation: 27
Context: Assume I have an application that shows a list of restaurants & 100000 restaurants to show. Each restaurant belong to a category.eg: Indian. I want to show the users the individual category they want to view.
approach 1: Add all restaurants to collection and save the document id in a array belonging to the specified category. So if I want all Indian restaurants I would just get the array Indian which will contain all the Indian restaurants Id's and load them.
approach 2:Add all restaurants to collection and give each document a category. So when the user needs list of Indian restaurants I would just use where() to filter them out. In this approach does firestore bill me for all 100000 document reads and is this approach efficient ?
Is there a better approach for this problem?
Upvotes: 0
Views: 26
Reputation: 317352
They are the same.
Firestore does not charge for documents that don't match a query. When you use a filter to match documents in a query, you are only charged reads for the documents returned from the query.
Use either approach and pick the one that works best for you.
Upvotes: 1