Firestore error: Cannot use multiple conditional where clauses on different properties

Viewed 1069

I'm tring to use multiple "where" filters on Firestore query, My query is based on the above example.

My query:

let colRef = firebase.firestore().collectionGroup('volumes')
colRef = colRef.where('days', 'array-contains', day)
colRef = colRef.where('start_time', '<=', time)
colRef = colRef.where('end_time', '>', time)
colRef = colRef.where('volume', '>', 0)
const snapshot = await colRef.get()

I'm receiving the above error:

Error: 3 INVALID_ARGUMENT: Cannot have inequality filters on multiple properties

I have checked about compounding Firestore queries and I found out that:

You can perform range (<, <=, >, >=) or not equals (!=) comparisons only on a single field

It's a huge limitation to Firestore queries. Am I missing an another option to implement that query?

Thanks!

1 Answers

Range condition in Firestore can only be applied on a single field. This is a hard limit, that is well documented (as you've already included in your question).

Firestore only offers APIs where it can meet its performance guarantees, the main one of which is that queries return results in a time that is only related to the amount of data returned and not to the amount of data that needs to be searched for these results.

If you need more flexible queries than Firestore offers, you should consider using another database. But you'll likely loose the Firestore performance guarantee with that other database.

Related