I have created a collection which has sub collection data. I want to filter from sub collection with a key.
Here is my document:
{
"_id" : ObjectId("5758098356e3930537af15dd"),
"manpower_data" : [
{
"_id" : ObjectId("5758098356e3930537af15de"),
"created" : ISODate("2016-06-08T12:03:15.387Z"),
"designation" : "Visiting Evaluator",
"evaluatorContactNumber" : "987654321",
"evaluatorName" : "Dumy User1",
"dealerCodeFor" : "ZSAE876",
"region" : "Gurgaon"
},
{
"_id" : ObjectId("5758098356e3930537af15de"),
"created" : ISODate("2016-06-08T12:03:15.387Z"),
"designation" : "Resident Evaluator",
"evaluatorContactNumber" : "987654321",
"evaluatorName" : "Dumy User2",
"dealerCodeFor" : "ZSAE877",
"region" : "Delhi"
}
]
}
When I run this query
db.mycollection.find({"manpower_data.dealerCodeFor":"ZSAE876"});
It returns me all two sub document but I want to get only those manpower data
which has matching dealerCodeFor
.