I need to query a firestore collection for entries where a start time (which is a number) is >= slot.start
and and <= slot.end
.
like this:
.collection('Entries', ref => ref.where('timeStart', '>=', slot.timeStart).where('timeEnd', '<=', slot.timeEnd))
but I get this error:
Invalid query. All where filters with an inequality (<, <=, >, or >=) must be on the same field.
I thought this query would work with composite index but as the error says that does not work.
When I change the query to this:
.collection('Entries', ref => ref.where('timeStart', '==', slot.timeStart).where('timeEnd', '<=', slot.timeEnd))
I can create an index for it. Furthermore when I change the 2nd '<=' to an '==' aswell I don't even need an index for it.
I didn't think my query is that advanced and I'm a little bit disappointed that firestore can't do this query. So what is the best solution for my problem? Is the next best thing to omit the 2nd query statement like this
.collection('Entries', ref => ref.where('timeStart', '>=', slot.timeStart))
And then iterate through the results and check if timeEnd <= entry.timeEnd
"manually"? That seems like a really bad solution for me because I may need to load a lot of data then.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…