问题
I am working on this project where I have to put data in maps inside in array for example:
[{Rate: 1.3, Title: "Test",...}]
What I would like to do to find documents which has maps inside their array with rating 1.3 and above without fetching all arrays and filtering it internally
I have tried to this
Firestore.instance
.collection("profiles")
.where("questions", arrayContains: {"Rate": 1.3})
.getDocuments(source: Source.serverAndCache)
this code actually requires me to put all map data so it could return true otherwise it will return false. What I want is just to filter data based on some of the map data
回答1:
The arrayContains operator checks for the complete element's presence in the array. So if your array contains an element {Rate: 1.3, Title: "Test"}, you need to:
.where("questions", arrayContains: {Rate: 1.3, Title: "Test"})
If you want to be able to test only for Rate, create an additional array Rates where you keep just those values. Then you can query with:
.where("rates", arrayContains: 1.3)
来源:https://stackoverflow.com/questions/57634679/how-to-make-query-spot-only-the-some-value-in-a-map-inside-an-array-in-flutter