Reputation: 3413
I was having a good time using Firestore but I'm now starting to think that using this product may be impractical as I am having a lot of challenges trying to query my data.
Ultimately, I am trying to to retrieve a list of geographical locations from a Firestore document by providing some filtration criteria (price range, date ranges, geographical bounds). Unfortunately, Firestore does not yet support multi range queries nor do they support geographical queries. Below are some things I have tried so far. I am using AngularFire2 for this implementation:
This works
@Effect() loadPostings: Observable<Action> = this.actions
.ofType<LoadPostings>(MapActionTypes.Load_Postings)
.switchMap(
latLngBound => this.firestoreDB.collection<Posting>('postings', ref => ref
.where('duration.min', '>=', 1) // --------> this works
).valueChanges()
.map(postings => new LoadPostingsSuccess(postings))
);
This works as well
@Effect() loadPostings: Observable<Action> = this.actions
.ofType<LoadPostings>(MapActionTypes.Load_Postings)
.switchMap(
latLngBound => this.firestoreDB.collection<Posting>('postings', ref => ref
.where('duration.max', '<=', 5) // ------> this works as well
).valueChanges()
.map(postings => new LoadPostingsSuccess(postings))
);
This Doesnt not work (for some reason)
@Effect() loadPostings: Observable<Action> = this.actions
.ofType<LoadPostings>(MapActionTypes.Load_Postings)
.switchMap(
latLngBound => this.firestoreDB.collection<Posting>('postings', ref => ref
.where('duration.min', '>=', 1) // ---> 2 range queries dont work :(
.where('duration.max', '<=', 5)
).valueChanges()
.map(postings => new LoadPostingsSuccess(postings))
);
These limitations do not come off as a surprise as the documentation explicitly says that this cannot be done. But how is this even offering? It seems like I'm trying to do a pretty basic query, am I wrong? How do I go about this? Should I abandon this and just make my own backend?
Upvotes: 0
Views: 744
Reputation: 598728
Geoqueries are not yet supported on Cloud Firestore. You already seem to know that, but I'll list some of the previous questions about it for reference:
If you're looking to do them today, then you should either consider using a database that has support for them (such as the Firebase Realtime Database does through the Geofire add-on library), or implement your own geoquerying mechanism (which would involve implementing geohashing, to get the lat/lon combination into a single field and then querying on ranges of that field. The latter is a very non-trivial exercise, so I'd recommend it only if the other two options (waiting or realtime database) aren't an option for you.
I don't think there's another way to do queries that have multiple range filgers. The problem is getting such queries to work in a horizontally scalable way. With a single range condition Firestore can do something similar to what I described here. With multiple ranges that won't work anymore. You'd essentially need to find a way to combine the values you want to filter on into a single value, similar to how a geohash combines lat and lon.
Upvotes: 1