skip to Main Content

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


  1. Firebase > Documentation > Firestore > Build > Geo queries

    Cloud Firestore only allows a single range clause per compound query,
    which means we can’t perform geo queries by simply storing latitude
    and longitude as separate fields and querying a bounding box.

    Solution: Geohashes
    Geohash is a system for encoding a (latitude, longitude) pair into a single Base32 string. In the Geohash system the
    world is divided into a rectangular grid.

    Install helper library
    Creating and parsing Geohashes involves some tricky math, so we
    created helper libraries to abstract the most difficult parts on
    Android, Apple, and Web:

    Login or Signup to reply.
  2. 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?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search