【问题标题】:The query requires an index, but i already create the index查询需要索引,但我已经创建了索引
【发布时间】:2020-03-25 03:08:06
【问题描述】:

我收到以下错误

W/Firestore(1034):(19.0.0)[Firestore]:监听查询(userChat 在哪里 == M-00710 订购 -messageDate, -name) 失败: Status{code=FAILED_PRECONDITION, description=查询需要一个 指数。你可以在这里创建它: https://console.firebase.google.com/v1/r/project/...,原因=null}

当我试图找到record时会发生这种情况

 void getReply() {
    var userQuery = databaseReference
        .collection(documentId)
        .where('to', isEqualTo: userId)
        .orderBy("messageDate", descending: true)
        .limit(1);
    userQuery.snapshots().listen((data) {
      data.documentChanges.forEach((change) {
        print('documentChanges ${change.document.data}');
      });
    });
  }

这是我的索引

我错过了什么吗?

【问题讨论】:

标签: firebase dart google-cloud-platform google-cloud-firestore


【解决方案1】:

您正在使用的查询将需要在“to”和“messageDate”字段上的复合索引,但您创建的索引似乎在“ from”和“messageDate”字段。

【讨论】:

    【解决方案2】:

    在集合 userChat 上创建一个复合索引,如下所示

    messageDate:DESC  to:ASC
    

    【讨论】:

      猜你喜欢
      • 2020-05-12
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 2020-02-02
      • 2020-05-22
      • 1970-01-01
      相关资源
      最近更新 更多