Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase 查询需要索引,但我已经创建了索引_Firebase_Dart_Google Cloud Platform_Google Cloud Firestore - Fatal编程技术网

Firebase 查询需要索引,但我已经创建了索引

Firebase 查询需要索引,但我已经创建了索引,firebase,dart,google-cloud-platform,google-cloud-firestore,Firebase,Dart,Google Cloud Platform,Google Cloud Firestore,我得到以下错误 W/Firestore(1034):(19.0.0)[Firestore]:监听查询(userChat) 其中to==M-00710 order by-messageDate,-name)失败: 状态{code=FAILED\u前提条件,description=查询需要 索引。您可以在此处创建它: …,原因=空} 它发生在我试图查找记录时 void getReply() { var userQuery = databaseReference .colle

我得到以下错误

W/Firestore(1034):(19.0.0)[Firestore]:监听查询(userChat) 其中to==M-00710 order by-messageDate,-name)失败: 状态{code=FAILED\u前提条件,description=查询需要 索引。您可以在此处创建它: …,原因=空}

它发生在我试图查找
记录时

 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}');
      });
    });
  }
这是我的索引


我遗漏了什么吗?

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

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

messageDate:DESC  to:ASC
可能重复的