问题
how to use where with orderBy in flutter.
any one can tell me how these indexes are working and how to properly create them.
Query query = Firestore.instance
.collection('clients')
.where('sequenceStatus', isEqualTo: sequenceName)
.orderBy('created', descending: true)
.limit(20);
W/Firestore(19854): (19.0.0) [Firestore]: Listen for Query(clients where sequenceStatus == quotes order by -created, -name) failed: Status{code=FAILED_PRECONDITION, description=The query requires an index. You can create it here: https://console.firebase.google.com/project/rigatoinfissitest/database/firestore/indexes?create_composite=ClFwcm9qZWN0cy9yaWdhdG9pbmZpc3NpdGVzdC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvY2xpZW50cy9pbmRleGVzL18QARoSCg5zZXF1ZW5jZVN0YXR1cxABGgsKB2NyZWF0ZWQQAhoMCghfX25hbWVfXxAC, cause=null}
回答1:
Follow below 5 steps or start from 3rd step after redirecting on above link you have posted in the question.
Go to your firebase console database
Select Indexes from there. Click on Add index.
Enter
clients(collection name) in Collection ID field.Add
sequenceStatus(where clause field) in 1st field and leave Ascending as it is.Add
created(orderby field) 2nd field and leave Ascending as it is.Click Create index.
Now, run your query. It will work just fine.
Cheers!
来源:https://stackoverflow.com/questions/57372921/how-to-use-where-with-orderby-in-flutter