0

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) ?

Zana Mustafa
  • 49
  • 1
  • 10

1 Answers1

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