firestore.where() on two fields at once

后端 未结 1 2023
一整个雨季
一整个雨季 2020-12-12 03:33

I have a firestore collection of the following documents:

[
  {
    start:       { geohash: \'u3qchtmpuy2d\' },
    destination: { geohash: \'u3qcjvxfh9cs\'          


        
相关标签:
1条回答
  • 2020-12-12 04:01

    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:

    • https://www.youtube.com/watch?v=mx1mMdHBi5Q
    0 讨论(0)
提交回复
热议问题