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.

3
  • Logical OR queries. In this case, you should create a separate query for each OR condition and merge the query results in your app. Commented Nov 5, 2018 at 12:52
  • It should be and AND query. With an OR query this, would not be a problem. Commented Nov 5, 2018 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 stackoverflow.com/q/50658651, stackoverflow.com/q/47581370, stackoverflow.com/q/47288921, stackoverflow.com/q/48027326 Commented Nov 5, 2018 at 15:14

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

This should be an AND Query not and OR, second comment on answer!
The point is Cloud Firestore does not support queries with range filters on different fields.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.