1

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.