search inside array with object mongodb 1

search inside array with object mongodb

db.users.find({awards: {$elemMatch: {award:'National Medal', year:1975}}})

Here is what the above code is Doing:
1. We’re using the $elemMatch operator to match the first element in the awards array.
2. The first element is matched against the query document {award:’National Medal’, year:1975}.
3. The query returns all documents where the first element in the awards array is the document {award:’National Medal’, year:1975}.

Similar Posts