【问题标题】:Where, Firestore queries on Flutter, doesnot have "notEqualTo" condition [duplicate]其中,Flutter 上的 Firestore 查询没有“不等于”条件 [重复]
【发布时间】:2020-01-16 12:48:09
【问题描述】:

我正在从 fire-store 获取数据我有一个订单对象,它的状态作为属性可以是“待定”、“正在交付”、“已交付”。

我想要做的是获得所有订单,除了状态为“已交付”的订单*。

如何使用 Where 子句做到这一点?

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

任何帮助将不胜感激

【问题讨论】:

标签: firebase flutter dart google-cloud-firestore


【解决方案1】:

您可以查看"Query limitations" section in the querying article

Cloud Firestore 不支持以下类型的查询:

  • 带有!= 子句的查询。在这种情况下,您应该将查询拆分为大于查询和小于查询。例如,虽然不支持查询子句where("age", "!=", "30"),但您可以通过组合两个查询得到相同的结果集,一个带有子句where("age", "<", "30"),一个带有子句where("age", ">", 30)
return _fs
        .collection('orders')
        .where('status', isGreaterThan: 'delivered')
        .where('status', isLessThan: 'delivered')
        .snapshots();

然而

如您所见,我删除了deliveryTime 上的范围过滤器,因为不可能explained here 那样对多个字段执行范围过滤器:

您只能对单个字段执行范围比较(<<=>>=),并且在复合查询中最多可以包含一个array-contains 子句[.]

【讨论】:

    猜你喜欢
    • 2020-08-18
    • 2020-03-20
    • 2021-05-23
    • 2020-11-22
    • 2018-08-02
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 2020-09-07
    相关资源
    最近更新 更多