How to make query spot only the some value in a Map inside an Array in flutter (dart)?

懵懂的女人 提交于 2020-07-22 06:30:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!