Reputation: 93
I am building chat application with backend firestore database with below structure.
I am fetching the data as mention below. Which return the list of channels my user id involve in field "userArray" and to fetch "lastUpdatedOn" data based on given date/time.
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;
}
Here in above case, it show me an error in android logcat that to create composite index. Creation of composite index done but still getting same error message.
2019-10-04 17:46:30.562 26824-27054/net.jayamsoft.chat W/Firestore: (21.1.1) [Firestore]: Listen for Query(Channels where userArray array_contains 90348324 and lastUpdatedOn >= Timestamp(seconds=1570189540, nanoseconds=484000000) order by lastUpdatedOn, name) failed: Status{code=FAILED_PRECONDITION, description=The query requires an index. You can create it here: 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: Listen failed. com.google.firebase.firestore.FirebaseFirestoreException: FAILED_PRECONDITION: The query requires an index. You can create it here: https://console.firebase.google.com/project/easychat-lthe/database/firestore/indexes?create_composite=Ck5wcm9qZWN0cy9lYXN5Y2hhdC1sdGhlL2RhdGFiYXNlcy8oZGVmYXVsdCkvY29sbGVjdGlvbkdyb3Vwcy9DaGFubmVscy9pbmRleGVzL18QARoNCgl1c2VyQXJyYXkYARoRCg1sYXN0VXBkYXRlZE9uEAEaDAoIX19uYW1lX18QAQ at com.google.firebase.firestore.util.Util.exceptionFromStatus(com.google.firebase:firebase-firestore@@21.1.1:121) at com.google.firebase.firestore.core.EventManager.onError(com.google.firebase:firebase-firestore@@21.1.1:131) at com.google.firebase.firestore.core.SyncEngine.handleRejectedListen(com.google.firebase:firebase-firestore@@21.1.1:378) at com.google.firebase.firestore.core.FirestoreClient.handleRejectedListen(com.google.firebase:firebase-firestore@@21.1.1:307) at com.google.firebase.firestore.remote.RemoteStore.processTargetError(com.google.firebase:firebase-firestore@@21.1.1:551) at com.google.firebase.firestore.remote.RemoteStore.handleWatchChange(com.google.firebase:firebase-firestore@@21.1.1:436) at com.google.firebase.firestore.remote.RemoteStore.access$100(com.google.firebase:firebase-firestore@@21.1.1:53) at com.google.firebase.firestore.remote.RemoteStore$1.onWatchChange(com.google.firebase:firebase-firestore@@21.1.1:176) at com.google.firebase.firestore.remote.WatchStream.onNext(com.google.firebase:firebase-firestore@@21.1.1:108) at com.google.firebase.firestore.remote.WatchStream.onNext(com.google.firebase:firebase-firestore@@21.1.1:38) at com.google.firebase.firestore.remote.AbstractStream$StreamObserver.lambda$onNext$1(com.google.firebase:firebase-firestore@@21.1.1:119) at com.google.firebase.firestore.remote.AbstractStream$StreamObserver$$Lambda$2.run(com.google.firebase:firebase-firestore@@21.1.1) at com.google.firebase.firestore.remote.AbstractStream$CloseGuardedRunner.run(com.google.firebase:firebase-firestore@@21.1.1:67) at com.google.firebase.firestore.remote.AbstractStream$StreamObserver.onNext(com.google.firebase:firebase-firestore@@21.1.1:110) at com.google.firebase.firestore.remote.FirestoreChannel$1.onMessage(com.google.firebase:firebase-firestore@@21.1.1:120) at io.grpc.ForwardingClientCallListener.onMessage(ForwardingClientCallListener.java:33) at io.grpc.ForwardingClientCallListener.onMessage(ForwardingClientCallListener.java:33) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1MessagesAvailable.runInContext(ClientCallImpl.java:563) at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428) at java.util.concurrent.FutureTask.run(FutureTask.java:237) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:272) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at com.google.firebase.firestore.util.AsyncQueue$SynchronizedShutdownAwareExecutor$DelayedStartFactory.run(com.google.firebase:firebase-firestore@@21.1.1:224)
Upvotes: 0
Views: 1311
Reputation: 938
Following the links to generate indexes that the error gives you should be the solution to your issue. It seems the error is requiring you to create 2 indexes.
Attempt to follow the exact links from the error and allow it to create the indexes.
That should work.
Let us know.
Upvotes: 2