Between StartDate and EndDate Firestore

No matter what is the platform that you are using for building your application, I'm sure that the error that you get is quite explicit. Cloud Firestore official documentation is also quite explicit regarding this topic. So there are some query limitations, when it comes to Firestore:

Cloud Firestore does not support the following types of queries:

  • Logical OR queries. In this case, you should create a separate query for each OR condition and merge the query results in your app.

So a Firestore query can perform a range filtering only on a single property. Since you are trying to filter ranges on two properties, you're geeting that error message and this is the expected behaviour since this is not possible in a single Firestore query.

To solve this, you can choose from one of the following solutions:

  • You can perform filtering on one (first) field in the query and on the other (second) field client-side, as also the official documentation indicates.

  • You can combine the values of the two range into a single field in some way that allows your use-case with a single field. A very successful example of such a combination would be the use of geohashes for filtering on latitude and longitude properties as Frank van Puffelen explained very well in this video, Querying Firebase and Firestore.

  • Another option is to change the way your are storing your data and model it differently. The most simple implementation would be to put all items within the startDate and endDate into a single collection. Since you didn't choose a tag for a platform, I will write the necessary query in Javascript but it can be simply written also for other programming languages. So you can query that collection with the following query:

      db.collection("startDate-endDate").where('date','>=', start).where('date','<=', end);
    
  • Another even more general alternative would be to store all your items in a collection for each periode you need (year, monts or days) separately, and then perform the necessary number of queries to get the items you are looking for one of each collection, itemsFromFirstYear, itemsFromSecondYear and so on.

Please take also take a look at the official documentation regarding:

  • document on compound queries and their limitations
  • video on Cloud Firestore queries.

IMHO, I'd recommend picking up the first option.