Home > front end >  Firestore: Query by item in array
Firestore: Query by item in array

Time:04-07

I have documents with field (of array type) for period (from, to):

Period

and I would like to filter documents by item in array of "period" field ... for example:

where('period.0', '>=', startOfYear(new Date()))

but it seems that this doesn't work ...

For example if period is a Map instead of Array, then this thing works:

where('period.start', '>=', startOfYear(new Date()))

But, I store this as an array, because output of UI component is an array and I don't have to map array to object, and later from object for array.

So the question is why this doesn't work with array, and if there is any plan, that this will be supported for arrays to?

CodePudding user response:

There is no operator to filter based on an item at a specific index in an array. If you need that, as you already said, you will need to put the relevant value from the array in a separate field and filter on that.

There are currently no plans to add such an operation, but you can always weigh in with a feature request.

  • Related