简体   繁体   中英

Query Firebase using Map value, Flutter

I'm trying to query to my Firebase collection using the value inside of Array. I'm using arrayContains and then passing the value like shown in the code, but after querying, it returns a length of 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 . You must use the entire student object to query using array-containing . This query tries to find {'studentid':'1WINXTQdshhn4jLfhMWWaZNNdL32'} object inside the array of users.0 field. Read more about this here https://firebase.google.com/docs/firestore/query-data/queries#array_membership .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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