【问题标题】:How to query integers in fields in Cloud Firestore using Flutter如何使用 Flutter 在 Cloud Firestore 中查询字段中的整数
【发布时间】:2020-07-14 19:18:03
【问题描述】:

我正在尝试弄清楚如何在 Cloud Firestore 中查询数字。这是我的代码:

final result = await Firestore.instance.collection('Social_Posts').where(30, isGreaterThan: "views").getDocuments();

我收到以下错误:

Unhandled Exception: 'package:cloud_firestore_platform_interface/src/method_channel/method_channel_query.dart': Failed assertion: line 119 pos 12: 'field is String || field is FieldPath': Supported [field] types are [String] and [FieldPath].

看起来 Cloud Firestore 查询只接受字符串。 如果是这样,那我怎么查询数字呢?

【问题讨论】:

    标签: firebase flutter dart google-cloud-firestore


    【解决方案1】:

    哎呀,很简单。

    只需执行以下操作:

    final result = await Firestore.instance.collection('Social_Posts').where("views", isGreaterThan: 30).getDocuments();
    

    【讨论】:

    • 是的,这是正确的。原因是您将 (views) 变量括在引号中,这意味着它引用字符串“views”而不是变量 (views) 的值
    猜你喜欢
    • 2020-08-23
    • 2022-01-23
    • 2019-08-06
    • 1970-01-01
    • 2019-08-23
    • 2021-07-29
    • 1970-01-01
    • 2023-01-22
    相关资源
    最近更新 更多