I have a mongo document like below
{
"_id" : ObjectId("588adde40fcbbbc341b34e1c"),
"title" : "Fifa world cup",
"tags" : [
{
"name" : "Football",
"type" : "Sports"
},
{
"name" : "World cup",
"type" : "Sports"
},
{
"name" : "Fifa",
"type" : "Manager"
}
]
}
I wrote the below query to get all the tags with type Sports
but I am only getting 1 item instead of 2
db.collection.find(
{
tags:
{
$elemMatch:
{
type: "Sports"
}
}
},
{
"tags.$" : 1
})
Is it possible to get all the matching items? What I am missing here?