Firestore-io.grpc.StatusException:FAILED_PRECONDITION:查询需要索引

时间:2019-10-04 12:36:34

标签: android firebase google-cloud-firestore

我正在使用具有以下结构的后端Firestore数据库构建聊天应用程序。

enter image description here

我正在按如下所述获取数据。该字段返回我的用户ID涉及的字段“ userArray”中的频道列表,并根据给定的日期/时间获取“ lastUpdatedOn”数据。

registration = fireStoreDb.collection(clsUtility.RootCollections.Channels.toString())
            .whereArrayContains("userArray", loggedInPsno)
            .whereGreaterThanOrEqualTo("lastUpdatedOn", lastChannelUpdateDateTime)
            .orderBy("lastUpdatedOn", Query.Direction.ASCENDING)
            .addSnapshotListener((queryDocumentSnapshots, e) -> {

                if (e != null) {
                    Log.w("loadUsers", "Listen failed.", e);
                    return;
                }

在上述情况下,它向我显示了创建复合索引的android logcat错误。创建了复合索引,但仍然收到相同的错误消息。

enter image description here

  

2019-10-04 17:46:30.562 26824-27054 / net.jayamsoft.chat W / Firestore:(21.1.1)[Firestore]:侦听查询(userArray array_contains包含90348324和lastUpdatedOn> = Timestamp( seconds = 1570189540,nanoseconds = 484000000)通过lastUpdatedOn排序,名称)失败:状态{code = FAILED_PRECONDITION,description =查询需要索引。您可以在此处创建它:https://console.firebase.google.com/project/easychat-lthe/database/firestore/indexes?create_composite=Ck5wcm9qZWN0cy9lYXN5Y2hhdC1sdGhlL2RhdGFiYXNlcy8oZGVmYXVsdCkvY29sbGVjdGlvbkdyb3Vwcy9DaGFubmVscy9pbmRleGVzL18QARoNCgl1c2VyQXJyYXkYARoRCg1sYXN0VXBkYXRlZE9uEAEaDAoIX19uYW1lX18QAQ,cause = null}   2019-10-04 17:46:30.567 26824-26824 / net.jayamsoft.chat W / loadUsers:监听失败。       com.google.firebase.firestore.FirebaseFirestoreException:FAILED_PRECONDITION:查询需要索引。您可以在这里创建它:https://console.firebase.google.com/project/easychat-lthe/database/firestore/indexes?create_composite=Ck5wcm9qZWN0cy9lYXN5Y2hhdC1sdGhlL2RhdGFiYXNlcy8oZGVmYXVsdCkvY29sbGVjdGlvbkdyb3Vwcy9DaGFubmVscy9pbmRleGVzL18QARoNCgl1c2VyQXJyYXkYARoRCg1sYXN0VXBkYXRlZE9uEAEaDAoIX19uYW1lX18QAQ           在com.google.firebase.firestore.util.Util.exceptionFromStatus(com.google.firebase:firebase-firestore @@ 21.1.1:121)           com.google.firebase.firestore.core.EventManager.onError(com.google.firebase:firebase-firestore @@ 21.1.1:131)           在com.google.firebase.firestore.core.SyncEngine.handleRejectedListen(com.google.firebase:firebase-firestore @@ 21.1.1:378)           在com.google.firebase.firestore.core.FirestoreClient.handleRejectedListen(com.google.firebase:firebase-firestore @@ 21.1.1:307)           com.google.firebase.firestore.remote.RemoteStore.processTargetError(com.google.firebase:firebase-firestore @@ 21.1.1:551)           在com.google.firebase.firestore.remote.RemoteStore.handleWatchChange(com.google.firebase:firebase-firestore @@ 21.1.1:436)           com.google.firebase.firestore.remote.RemoteStore.access $ 100(com.google.firebase:firebase-firestore @@ 21.1.1:53)           com.google.firebase.firestore.remote.RemoteStore $ 1.onWatchChange(com.google.firebase:firebase-firestore @@ 21.1.1:176)           请访问com.google.firebase.firestore.remote.WatchStream.onNext(com.google.firebase:firebase-firestore @@ 21.1.1:108)           在com.google.firebase.firestore.remote.WatchStream.onNext(com.google.firebase:firebase-firestore @@ 21.1.1:38)           com.google.firebase.firestore.remote.AbstractStream $ StreamObserver.lambda $ onNext $ 1(com.google.firebase:firebase-firestore @@ 21.1.1:119)           com.google.firebase.firestore.remote.AbstractStream $ StreamObserver $$ Lambda $ 2.run(com.google.firebase:firebase-firestore @@ 21.1.1)           在com.google.firebase.firestore.remote.AbstractStream $ CloseGuardedRunner.run(com.google.firebase:firebase-firestore @@ 21.1.1:67)           在com.google.firebase.firestore.remote.AbstractStream $ StreamObserver.onNext(com.google.firebase:firebase-firestore @@ 21.1.1:110)           在com.google.firebase.firestore.remote.FirestoreChannel $ 1.onMessage(com.google.firebase:firebase-firestore @@ 21.1.1:120)           在io.grpc.ForwardingClientCallListener.onMessage(ForwardingClientCallListener.java:33)           在io.grpc.ForwardingClientCallListener.onMessage(ForwardingClientCallListener.java:33)           在io.grpc.internal.ClientCallImpl $ ClientStreamListenerImpl $ 1MessagesAvailable.runInContext(ClientCallImpl.java:563)           在io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)           在io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)           在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:428)           在java.util.concurrent.FutureTask.run(FutureTask.java:237)           在java.util.concurrent.ScheduledThreadPoolExecutor $ ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272)           在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)           在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:607)           com.google.firebase.firestore.util.AsyncQueue $ SynchronizedShutdownAwareExecutor $ DelayedStartFactory.run(com.google.firebase:firebase-firestore @@ 21.1.1:224)

2 个答案:

答案 0 :(得分:1)

按照链接生成错误为您提供的索引,应该可以解决您的问题。似乎该错误要求您创建2个索引。

尝试按照错误的确切链接进行操作,并允许其创建索引。

应该可以。

让我们知道。

答案 1 :(得分:0)

密钥不得在Firebase的JSON中重复 “ lastUpdatedOn”