I'm trying to match some values in an array of documents. But i got no luck to do it. This is the document:
{
"student": "Pedro",
"class_id": 10,
"scores": [
{
"type":"exam",
"score": 10
},
{
"type":"homework",
"score": 10
}
]
}
I want to match the scores.score where is an exam, i have tried this
db.class.aggregate(
{
$unwind: "$scores"
},
{
$group: {
_id: "$class_id"
}
},
{
$match:{
"$scores.score": "exam"
}
}
)
But it doesn't work, any suggestion?