How to do search using elemMatch on array of SubDocument? I have document called ReportCollection with elements such as:-
/* 0 */
{
"_id" : ObjectId("5507bfc435e9470c9aaaa2ac"),
"owner" : ObjectId("5507bfc31e14d78e177ceebd"),
"reports" : {
"xReport" : [
{
"name" : "xReport",
"parameters" : {
"x" : {
"dateTime" : "2015-03-11T18:30:00.000Z",
"unit" : 1,
"value" : 102
}
},
"createdBy" : ObjectId("5507bfc31e14d78e177ceebd"),
"modifiedBy" : ObjectId("5507bfc31e14d78e177ceebd"),
"_id" : ObjectId("5507bfc41e14d78e177ceebf")
}
]
}
}
I got reports.xReport[]._id as search parameter.
My following attempt is failing :-
db.reports.find ({ {owner: ObjectId("5507afd3d54bae3513c185cb")},
{ 'reports.xReport': {$elemMatch: {_id: ObjectId("5507afd3d54bae3513c185cd") }}} } )