Reputation: 14266
I am running a simple query on a small test database, this is my query:
_firestore.collection('chats')
.where('users', arrayContains: userId)
.orderBy('sentDate', descending: true)
.snapshots();
My database is at Cloud Firestore location southamerica-east1 and it looks like this (blurred some data for security reasons):
I am using the Firestore plugin for Flutter on Android, so the underlining platform will be Android.
If I remove the .where('users', arrayContains: userId)
my query runs immediately and if I change any fields on the database (like if I use the Firestore console and change Chat 1
to Chat 2
), the updates appear immediately. But with the where
clause, updates take around 42 seconds to appear.
The database is very small and doesn't have more than 15 items.
Is this normal behavior? If not, how can I fix this?
I am not running any code on top of this query, I just get it and display its results, using a simple DTO and very fast UI code, if I remove the where
clause, I get all the 15 documents displayed instantaneously. My latency is fine, I have a strong internet connection, everything is blazingly fast, until I just add this simple where
line and everything stops working.
Upvotes: 0
Views: 946
Reputation: 14266
Firestore provides error messages when there's a missing index, with a link for creating the index.
The problem I was facing was that the error messages were being printed at the Logcat output, whereas with Flutter we use the Debug Console, so the error messages weren't appearing at all and I thought my idexes were fine.
I already filed a bug for the Cloud Firestore Flutter team, so they can at least updated the Getting Started docs, and point out that any missing indexes errors will be printed on Logcat (at least for Android).
PS: I still didn't test the query itself as the indexes are still building. I have to point out that even though the Firestore Console say there are built and ready, I get error messages saying I have to wait until they finish building.
Upvotes: 1