本文介绍了如何使用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 worksbut 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:

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.

  • Click Create.

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

10-30 12:38