【问题标题】:The initial orderBy() field "[[FieldPath([id]), true]][0][0]" has to be the same as the where() field parameter初始 orderBy() 字段“[[FieldPath([id]), true]][0][0]”必须与 where() 字段参数相同
【发布时间】:2021-09-10 22:23:50
【问题描述】:

同时执行 Orderby 和 Query 时 Firestore 颤动给出错误

我不知道它的包或查询。当

      body: PaginateFirestore(
        itemBuilderType: PaginateBuilderType.listView,
        itemBuilder: (index, context, documentSnapshot) {
          final data = documentSnapshot.data() as Map?;
          // final sub = data.
          return InkWell(
            onTap: () {},
            child: ListTile(
              leading: CircleAvatar(child: Icon(Icons.person)),
              title: data == null ? Text('Error in data') : Text(data['id']),
            ),
          );
        },
        // orderBy is compulsory to enable pagination
        query: FirebaseFirestore.instance.collection('Phones').where('price',isGreaterThan:'560' ).orderBy('id',descending: true),
        // to fetch real-time data
        isLive: true,
      ),
    );
  }
  

运行代码时出错

    The following assertion was thrown building Retrive(dirty):
The initial orderBy() field "[[FieldPath([id]), true]][0][0]" has to be the same as the where() field parameter "FieldPath([price])" when an inequality operator is invoked.
'package:cloud_firestore/src/query.dart':
Failed assertion: line 484 pos 13: 'conditionField == orders[0][0]'

【问题讨论】:

  • 是的,这里列出了这个限制:firebase.google.com/docs/firestore/query-data/…
  • 那么是string = string scene还是field = field to read + query + orderby
  • 恐怕我根本不明白那个评论。 (但从根本上说,您试图按一个字段过滤并按另一个字段排序,这是不支持的。)

标签: flutter google-cloud-firestore


【解决方案1】:

初始 orderBy() 字段“[[FieldPath([id]), true]][0][0]”必须 与 where() 字段参数“FieldPath([price])”相同时 调用不等式运算符。

这意味着第一个orderBy 必须是您执行不等式查询的字段,即price

  • 从以下位置更新您的查询:
query: FirebaseFirestore.instance.collection('Phones').where('price',isGreaterThan:'560' ).orderBy('id',descending: true)

到:

query: FirebaseFirestore.instance.collection('Phones').where('price',isGreaterThan:'560' ).orderBy('price').orderBy('id',descending: true)
  • 运行此查询,您将在控制台上收到一条消息以及一个链接,说明您需要创建一个index

  • 点击链接并创建索引。

  • 等待索引完成创建过程并再次运行查询。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-25
  • 2020-04-21
  • 2021-05-15
  • 1970-01-01
  • 2018-01-26
  • 2021-07-06
相关资源
最近更新 更多