I've got a collection were documents have nested arrays, and I would like to select only the lower arrays, is it possible?
I have tried this but it doesn't work:
db.collection.find({},{'family.children.$.toys' :1})
document example
{
"id":1000,
"name": "Bob",
"surname":"The Builder",
"family":{
"size":2,
"status": "happy",
"children":[{
"name":"Jim",
"school": "St. Mary",
"toys":[{
"name":"Lego"
},
{
"name":"Playstation"
}]
},
{
"name":"Kate",
"school": "St. Mary",
"toys":[{
"name":"Xbox"
},
{
"name":"Barbie"
}]
}
]
}
}
Expected result (extract only toys list):
{
_id:1000,
family:{
childrens:[{
toys:[{
name:Lego
},
{
name:Playstation
}]
},
{
toys:[{
name:Xbox,
},
{
name:Barbie
}]
}
]
}}