I have orders collection in firestore which have status field (String), status field have those string (Pending, Cooking, Cooked, Shipped, Delivered), I want to query to get only those document which have status (Pending, Cooking, Cooked) ?
Asked
Active
Viewed 642 times
1 Answers
0
There is no Firestore equivalent of a SQL SELECT * FROM Collection WHERE status IN (Pending, Cooking, Cooked). The closest that Firestore has is to allow a range query, as Tim shows here. But that will only work if the values (Pending, Cooking, Cooked) are consecutive in the range. If they're not, you'll have to perform multiple queries.
Since these values sound like they might be steps in a process, you could consider prefixing them with a "step number": 1_Pending, 2_Cooking, 3_Cooked. With those it becomes a lot easier to query a range of steps. Alternatively you could also add an additional stepNumber property, but you'd have to keep that in sync with the step name.
Frank van Puffelen
- 565,676
- 79
- 828
- 807
-
So it will be better if I use Interger value instead of strings? – Zana Mustafa Jan 09 '18 at 14:24
-
If that makes it easier to ensure the values you want are in a range, it may help. But in that can you could also simply prefix the string with the same numbers (`1_Pending, 2_Cooking, 3_Cooked`) and filter on prefixes or add a field (e.g. step) and filter on that. – Frank van Puffelen Jan 09 '18 at 15:17
-
Thanks. prefix will be better :) – Zana Mustafa Jan 09 '18 at 15:21