简体   繁体   English

使用 Map 值查询 Firebase,Flutter

[英]Query Firebase using Map value, Flutter

I'm trying to query to my Firebase collection using the value inside of Array.我正在尝试使用数组中的值查询我的 Firebase 集合。 I'm using arrayContains and then passing the value like shown in the code, but after querying, it returns a length of 0.我正在使用 arrayContains,然后传递代码中所示的值,但在查询之后,它返回的长度为 0。

FirebaseFirestore.instance
.collection('chatrooms')
.where('users.0', arrayContains: {'studentid':'1WINXTQdshhn4jLfhMWWaZNNdL32'})
.get();

Here's an image of my database.这是我的数据库的图像。

Database Collection数据库集合

This cannot be done using array-contains .这不能使用array-contains来完成。 You must use the entire student object to query using array-containing .您必须使用整个学生 object 来使用array-containing进行查询。 This query tries to find {'studentid':'1WINXTQdshhn4jLfhMWWaZNNdL32'} object inside the array of users.0 field.此查询尝试在users.0字段数组中查找{'studentid':'1WINXTQdshhn4jLfhMWWaZNNdL32'} object。 Read more about this here https://firebase.google.com/docs/firestore/query-data/queries#array_membership .在此处阅读更多相关信息https://firebase.google.com/docs/firestore/query-data/queries#array_membership

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM