【问题标题】:The initial orderBy() field '[[FieldPath([ID]), true]][0][0]' has to be the same as the where()初始 orderBy() 字段 '[[FieldPath([ID]), true]][0][0]' 必须与 where() 相同
【发布时间】:2022-02-02 19:08:30
【问题描述】:

谁能帮我构建这个查询,一切正常,但是一旦我输入年龄范围查询,它就会抛出一个错误,这是我的查询

                fireStore
                .collection('TestUsers')
                .where('Country', isEqualTo: 'Mexico')
                .where('ID', whereNotIn: [
                  '9f8fe3c0-83fb-11ec-ba7d-71eedc0beebe',
                  '3eb69ae0-83fa-11ec-b4a4-cba7e6a8918b'
                ])
                .orderBy('ID', descending: true)
                .where('DOB',
                    isLessThan: minAgeToQueryWith,
                    isGreaterThan: maxAgeToQueryWith)
                .orderBy('DOB', descending: true)
                .where('Gender', isEqualTo: 'Gender Fluid')
                .orderBy('BoostDate', descending: true)
                .orderBy('Points', descending: true),

这是我得到的错误

初始 orderBy() 字段 '[[FieldPath([ID]), true]][0][0]' 必须与 where() 字段参数 'FieldPath([DOB])' 相同时调用不等式运算符。 '包:cloud_firestore/src/query.dart': 断言失败:第 677 行 pos 11: 'field == orders[0][0]'

【问题讨论】:

    标签: firebase flutter google-cloud-firestore querying


    【解决方案1】:

    你需要把where放在第一个,orderby放在最后

    解决办法

    fireStore
                    .collection('TestUsers')
                    .where('Country', isEqualTo: 'Mexico')
                    .where('ID', whereNotIn: [
                      '9f8fe3c0-83fb-11ec-ba7d-71eedc0beebe',
                      '3eb69ae0-83fa-11ec-b4a4-cba7e6a8918b'
                    ])
                   
                    .where('DOB',
                        isLessThan: minAgeToQueryWith,
                        isGreaterThan: maxAgeToQueryWith)
                    .where('Gender', isEqualTo: 'Gender Fluid')
                    .orderBy('BoostDate', descending: true)
                    .orderBy('Points', descending: true)
                    .orderBy('ID', descending: true)
                    .orderBy('DOB', descending: true)
    

    它必须有效,但如果 orderBy 的字段在逻辑上不相等,那么您只需放置一个 .orderBy 查询

    【讨论】:

    • No 如果我删除 boostDate 和 Points 则不起作用) 它抛出初始 orderBy() 字段 "[[FieldPath([ID]), true]][0][0]" 必须与 where() 字段参数 "FieldPath([DOB])" 相同时调用不等式运算符。 'package:cloud_firestore/src/query.dart':断言失败:第 485 行 pos 13:'conditionField == orders[0][0]'
    • ('DOB', isLessThan: 2004, isGreaterThan: 1960) 你只能使用一个比较!你不能使用浴 isLessThan, isGreaterThan
    • 我能做些什么来获取年龄范围然后我制作一个约会应用程序,用户可以在其中选择最小和最大年龄我可能错了,但我认为“Firestore 查询只能在单个字段上执行范围过滤. ' 并且我在单个字段上做范围
    • 在单独的 orderby 方法中使用它,,记住,数据必须与你使用的所有 orderby 的逻辑相等,并且它们在逻辑上没有反转
    • 我可能错了,但我认为'Firestore 查询只能对单个字段执行范围过滤。 ' 更新:- 也这样做 .where('DOB', isGreaterThan: 2000) 会引发相同的错误,并且我在单个字段上做范围
    猜你喜欢
    • 2021-09-10
    • 1970-01-01
    • 1970-01-01
    • 2020-01-04
    • 2018-12-07
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    相关资源
    最近更新 更多