Recently I've been playing around with Geohashes and Firestore. My todo scenario is to have a collection of documents (restaurants) and each restaurant will have list of Geohashes which delivers to.
I want to avoid adding the geoashes in the document restaurant as the document can be many times bigger than it should be.
The initial idea is to have all of the geohashes in a subcollection of the restaurant document but I found out its not possible to perform queries in subcollection of documents.
The second idea was to extract the geohashes to top level in a collection of delivery areas.
document:{ restaurantName: "aRestaurant",
deliveryArea: Arraylist<String> }
The problem in this scenario is that I will get back a list of restaurant names, where then I need to query the restaurants collection to get them and as far as I know I cannot perform OR operations in the queries.
It is my first time playing around with document databases and Firestore. Any guidance will be much appreciated.
firebaser here
Our original GeoFire library for the Firebase Realtime Database solved precisely this problem by having a separate top-level node for the geohashes. Each key under that node would typically correspond to the key of an actual entity in another top-level node.
So something like:
locations
key1: { g: "sa7ads", l: [ 14.5232, -156.17843 ] },
key2: { g: "fds347", l: [ -127.172, 167.1324 ] }
restaurants
key1: { name: "This is the first restaurant", ... },
key2: { name: "This is the second restaurant", ... },
With this structure, you perform a geoquery on /locations and then read the additional information of each restaurant in range from /restaurants/$key. That scaled quite well.
I'd recommend the same approach with Cloud Firestore. You'd have two top-level collections: one with the (smaller) location data, and one with the (bigger) additional data about each restaurant. This reduces the amount of data you read, although you will end up reading more documents. You'll have to balance these two (bandwidth vs. document reads) off against each other.
A few months ago I gave a talk about performing geoqueries on Cloud Firestore that might be worth checking out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With