2

We are building a app where we need to show nearby posts, made by users. A post should only be shown, if it is not more as 4 hours since posting. Because firestore doesn't provide geoquerys, i have to do a search, where all posts in a specific square are returned. This is my current query:

collection("posts")
        .where("creation", isGreaterThan: DateTime.now().subtract(Duration(hours: 4)))
        .where("location", isLessThan: cornor1OfSquare)
        .where("location", isGreaterThan: cornor2OfSquare)

The problem with this query is, that it's not allowed to add multiple where statements filtering on different fields.

Filtering by one property locally and one on the server side is not possbile, because we have millions of posts in our app.

Is there any other way to do this? For example restructure the data on the server, to make queries like this possible? I researched, but only found solutions, with "simple" data. But i have a Timestamp and a GeoPoint field, which makes it more complex.

The second approach, which comes to my mind, is to use cloud functions, but i have no idea how to do that, and if it is the best solution available.

I am programming in Dart/Flutter.

Niklas Raab
  • 1,576
  • 1
  • 16
  • 32
  • `Logical OR queries. In this case, you should create a separate query for each OR condition and merge the query results in your app.` – niclas_4 Nov 05 '18 at 12:52
  • It should be and AND query. With an OR query this, would not be a problem. – Niklas Raab Nov 05 '18 at 12:56
  • This type of query is not possible on Cloud Firestore at the moment, since it would be impossible to deliver results under Firestore's performance guarantees. Also see https://stackoverflow.com/q/50658651, https://stackoverflow.com/q/47581370, https://stackoverflow.com/q/47288921, https://stackoverflow.com/q/48027326 – Frank van Puffelen Nov 05 '18 at 15:14

1 Answers1

1

The Cloud Firestore doesn't support range filters on different fields. You most create separate query for each OR condition and merge the query results.

See this link for more: https://firebase.google.com/docs/firestore/query-data/queries?hl=en-us

Samuel Silva
  • 667
  • 6
  • 4