2

I am fetching a data from fire-store I have an order Object which have a status as an attribute that can be "pending"," delivering","delivered".

What I want to do is getting all the orders except the one with status "delivered"*.

How I can do that with Where clause ?

return _fs
        .collection('orders')
       // .where('status', ' ', 'delivered')
        .where('deliveryTime', isGreaterThan: startTime)
        .where('deliveryTime', isLessThan: endTime)
        .snapshots();

any help will be appreciated

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402
Aya Elsisy
  • 2,029
  • 4
  • 13
  • 23
  • Firestore queries cannot filter for fields that do not have a certain value. See https://stackoverflow.com/questions/47251919/firestore-how-to-perform-a-query-with-inequality-not-equals, and https://stackoverflow.com/questions/47195122/firestore-comparison-operators-contains-does-not-contain-starts-with – Frank van Puffelen Sep 15 '19 at 13:55

1 Answers1

-1

You can view the "Query limitations" section in the querying article:

Cloud Firestore does not support the following types of queries:

  • Queries with a != clause. In this case, you should split the query into a greater-than query and a less-than query. For example, although the query clause where("age", "!=", "30") is not supported, you can get the same result set by combining two queries, one with the clause where("age", "<", "30") and one with the clause where("age", ">", 30).
return _fs
        .collection('orders')
        .where('status', isGreaterThan: 'delivered')
        .where('status', isLessThan: 'delivered')
        .snapshots();

However

As you can see, I removed the range filter on deliveryTime because it is impossible to perform range filters on multiple fields as explained here:

You can only perform range comparisons (<, <=, >, >=) on a single field, and you can include at most one array-contains clause in a compound query[.]

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402