I am developing an Uber Eats like app for a project. Clients(restaurants) add Menus and menu items(products) into the cloud firestore database. Users (app users who search for restaurants and menu items) can search for restaurants and menu items in their nearby locations. Currently I am saving all the products that clients are uploading in a single collection. (Products collection). When the user tries to search menu items by location I have used
.where("location", isEqualTo:location)
My concern is when the products collection gets bigger over time (expecting up to 15000 products) would the query time and write and reads count go up and slows down the app?
What would be the best way to store products, which can be efficiently queried by its location?
2
Answers
Firebase > Documentation > Firestore > Build > Geo queries
Firestore query performance will remain same irrespective of number of documents your collection has. However, you should implement pagination in your app so all query results are not loaded at once (just like downloading a large file). Fetching documents in pages of 20-30 should be good and does not load further docs unless user asks for more results.
Also, checkout How do queries work in Cloud Firestore?
For GeoQueries, see How to run a geo "nearby" query with firestore?