1

In my current setup there are numerous event details in the events collection objects. I wish to display them in the order of their starting times, and i also want to set a condition on them that if the current time is past the end time then i dont want to include them in my query.

But Firestore throws an error that i cannot order by 'Start' field and set a 'where' condition on the 'End' field.

Can someone guide me in this as to what my approach should be over here to tackle this situation?

My query looks like this

var query = DatabaseService()
        .eventCollection
        .orderBy('start')
        .where('end',
            isGreaterThanOrEqualTo: DateTime.now().millisecondsSinceEpoch)
        .where('isDeleted', isEqualTo: false)
        .limit(eventsLoadLimit);

This shows up in the console log i dont think it can be solved using indices otherwise it provides with a link to create one itself inside of the error

Log: [ERROR] [UPCOMING EVENTS -> LATESTEVENTS LIST]: PlatformException(error, Invalid query. You have an inequality where filter (whereLessThan(), whereGreaterThan(), etc.) on field 'end' and so you must also have 'end' as your first orderBy() field, but your first orderBy() is currently on field 'start' instead., null)

3
  • There is a link to create the index right in the error message, isn't there? ` console.firebase.google.com/v1/r/project/ombre-dev/firestore/…, null)` Jun 5, 2020 at 21:10
  • I have edited the error message and updated with the actual one.
    – Aadiyaara
    Jun 5, 2020 at 21:13
  • That error message sounds pretty explicit to me: in order to filter on end, you must also (first) order on end. If you want to show the results in a different order, you'll have to post-process them in yoru application code. Jun 5, 2020 at 22:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.