3

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!

genericUser
  • 4,417
  • 1
  • 28
  • 73

1 Answers1

2

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    It's a bit disapponted since in some cases performance is not required, but price effiecency does. I would preffer that Firestore costs will be based more on resources preformance (such as CPU and RAM), than reads amount. Not accurate quiring is causing not effective reads which costs a lot of money even for small applications. I think Firebase has a huge potential, but it must change it pricing to based more on resources. Thanks for your honest answer. – genericUser Dec 21 '20 at 17:21
  • The lack of support for this operation has nothing to do with cost, and is purely because of performance. Since the Firestore engineers have not found a way to guarantee performance on multi-field range queries, they are not supported. – Frank van Puffelen Dec 21 '20 at 19:23
  • 1
    Why costumers are billed for something which is not a resource? (like CPU, RAM, bandwidth etc...). Firestore "reads" is not a resource, it is just a way to get more money. I prefer to be billed more on resources that I use and not "reads", "writes" or "deletes". Costumers "reads" is a very expensive service on Firestore and it is unjustified. I can read a document with a million lines, unefficiently or I can get one small document by DocId and I will be BILLED THE SMAE. Which is not make any sense. – genericUser Dec 21 '20 at 20:18