I have documents like this:
{
"_id" : ObjectId("53340d07d6429d27e1284c77"),
"worktypes" : [
{
"name" : "Pompas",
"works" : [
{
"name" : "work 1",
"code" : "0001"
}
]
},
{
"name" : "Pompas "",
"works" : [
{
"name" : "work 2",
"code" : "0002"
}
]
}
]
}
I did a query for get ONLY the works of one of worktype for this document, this is the query:
db.categories.find({$and: [
{ "_id": ObjectId('53340d07d6429d27e1284c77')},
{"worktypes.name": "Pompas"}
]},{"worktypes.works.$":1})
But i got
{
"_id" : ObjectId("53340d07d6429d27e1284c77"),
"worktypes" : [
{
"name" : "Pompas",
"works" : [
{
"name" : "work 1",
"code" : "0001"
}
]
}
]
}
But i only need:
"works" : [
{
"name" : "work 1",
"code" : "0001"
}
]
How can i reduce this?