Skip to content Skip to sidebar Skip to footer

Firestore.where() On Two Fields At Once

I have a firestore collection of the following documents: [ { start: { geohash: 'u3qchtmpuy2d' }, destination: { geohash: 'u3qcjvxfh9cs' }, timestamp: '28 Jun

Solution 1:

According to the official documentation regarding query limitations:

Query limitations

Cloud Firestore does not support the following types of queries:

  • Queries with range filters on different fields, as described in the previous section.

So as you can see, Cloud Firestore can only do a range filter on a single field and not on multiple fields as you intended to do. The most reasonable explanation is that Firestore cannot guarantee its performance in this case. Firestore must be able to return all results of a query in a single stream.

To solve this, you'll have to query the database twice and combine the results of those queries client side. It's not perfect, since you need to query twice but I think it will do the trick.

Please also note, that querying using range filters on geohashes will not return very accurate results. For that, I recommend you see Frank van Puffelen's remarkable video regarding this topic:

Post a Comment for "Firestore.where() On Two Fields At Once"