When using orderBy and startAfterDocument in the same query, I get the following error:
failed: Status{code=FAILED_PRECONDITION, description=The query requires an index. You can create it here: https://console.firebase.goog...
This error is being caught when I try to receive the next set of documents. Tried to create an index using the link provided in the error but it's a single index using the 'finalTimeStamp' field is being generated and firestore throws out the following exception.
this index is not necessary, configure using single field index controls
In my single field indexes, the descending index for a collection scope is already enabled.
My code:
if (_lastVisible == null) {
try {
data = await chatList
.document(widget.currentUserId)
.collection('inbox')
.orderBy('finalTimeStamp', descending: true)
.limit(10)
.getDocuments();
} catch (e) {
print('caught error 1');
}
} else {
try {
data = await chatList
.document(widget.currentUserId)
.collection('inbox')
.orderBy('finalTimeStamp', descending: true)
.startAfterDocument(_lastVisible)
.limit(10)
.getDocuments();
} catch (e) {
print('caught error 2');
}
}