I encountered a weird problem when I tried to find a specific subdocument. For example, I have a collection named "test" with a document looks like:
{
"_id": ObjectId("55af71b52028d8a365430fcd"),
"sub": [{
"name": "A",
"type": "2",
"score": "10"
}, {
"name": "B",
"type": "2",
"score": "9"
}]
}
When I tried using query like db.getCollection('test').find({"sub.score" : "9","sub.type" : "2"},{"sub.$" :1})
to find the second subdocument, I got the first subdocument instead
{
"_id": ObjectId("55af71b52028d8a365430fcd"),
"sub": [{
"name": "A",
"type": "2",
"score": "10"
}]
}
Is it the expected result from the query? Why I get the first subdocument instead of the second subdocument, meanwhile the first subdocument score isn't the same as score in the query?