I have the following data structure in Firestore
- runners (Collection)
-- uid_1 (Document)
--- name: James
--- height: 170
--- weight: 54
--- runTimeInSeconds: [ 540, 533, 530, 500 ] // this is array of 4
-- uid_2 (Document)
--- name: Larry
--- height: 168
--- weight: 51
--- runTimeInSeconds: [ 521, 611, 501 ] // this is array of 3 runs
-- uid_3 (Document)
--- name: Ben
--- height: 180
--- weight: 76
--- runTimeInSeconds: [ 621, 533 ] // this is array of 2 runs
I want to get the following documents (where runTimeInSeconds is greater than 600) in this order: uid_2 followed by uid 3. But I do not want to see uid_1.
What firestore query should I write?
I tried:
runnersRef.where("runTimeInSeconds", ">", 600) // this does not work.
You can't do range queries on values in lists. The index created for list items doesn't work that way. It can only detect that values in lists exist, when using the array_contains operator. If you want to use a range operator, you will actually need to split each field list item into a new collection with separate documents for each item. Each document should have a field with the duration field as a number. You can then duplicate the other fields into each document, or just store a reference to the original document for the runner.