Grokking MongoDB
0% completed
Query an Array
Here is a filter that compares a field with a single word, run against a field that holds a list of words.
db.users.find({ hobbies: "reading" }, { name: 1, _id: 0 })
[ { name: 'Alice' }, { name: 'Charlie' } ]
The filter matched because MongoDB compared "reading" with each element of the hobbies array, and one matching element was enough. This rule, that a condition on an array is tested against its elements, explains most of how array queries behave
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%