如何使用orderBy()和Where()相同?(颤振网) [英] how to use orderBy() and Where() same? (Flutter Web)

查看:51
本文介绍了如何使用orderBy()和Where()相同?(颤振网)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不加载数据,但无限期加载♾如果我起飞OrderBy,那么它可以工作但我需要订购者

代码:

  body:StreamBuilder< QuerySnapshot>(流:FirebaseFirestore.instance.collection(粉碎").where("user",isEqualTo:user.email).orderBy("date",降序:true).snapshots(),建造者:(BuildContext上下文,AsyncSnapshot< QuerySnapshot>快照){如果(!snapshot.hasData){ 

解决方案

当您执行这样的复合查询时,您需要创建的"Firestore"部分.>

  • 转到索引标签,然后点击创建索引.
  • 输入集合名称,并设置要用来对索引进行排序的字段.

对于非数组和非地图字段,即使您不需要该字段进行排序,也必须选择升序或降序.您的选择不会影响查询中的平等行为.

  • 点击创建.

Not load data but it loads indefinitely ♾ if i take off OrderBy then it works but I need the Order by

code:

body: StreamBuilder<QuerySnapshot>(
      stream: FirebaseFirestore.instance
          .collection("crush")
          .where("user", isEqualTo: user.email)
          .orderBy("date", descending: true)
          
          .snapshots(),
      builder:
          (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
        if (!snapshot.hasData) {

解决方案

When you do composite query like this you need to create composite index. There are two ways to create index for it:

Create index using error message:


When you try to use a compound query without existing index, you will get an error in your debug console like this:

E/flutter (23618): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [cloud_firestore/failed-precondition] The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/yourprojectname/firestore/indexes?create_composite=Ck1wcm9qZWN0cy92b2lkY2hhdGJldGEvZGF0YWJhc2VzLyhkZWZhdWx0KS9jb2xsZWN0aW9uR3JvdXBzL2NvbnRhY3RzL2luZGV4ZXMvXxABGgsKB3VzZW5hbWUQARoGCgJpZBABGgwKCF9fbmFtZV9fEAE

this error have a link to create a missing index with Firebase console. Follow this link, check data and click create.

Manually create index with Firebase console:


  • Go to indexes tab and click Create Index.
  • Enter the collection name and set the fields you want to order the index by.

For non-array and non-map fields, you must select ascending or descending ordering, even if you don't need the field for ordering. Your choice doesn't impact the behavior of equalities in the query.

  • Click Create.

这篇关于如何使用orderBy()和Where()相同?(颤振网)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆