I have an array containing objects.
These objects have a name and a color. Some objects can also contain children! (an array of other objects).
{
items : [
{
name: 'box'
color: 'red'
},
{
name: 'circle'
color: 'blue'
children: [
{
name: 'sphere'
color: 'orange'
},
{
name: 'polygons'
color: 'green'
}
]
},
{
name: 'triangle'
color: 'pink'
}
]
}
I need to retrieve all the names of these items and exclude their colors.
The result should be:
items : [
{
name: 'box'
},
{
name: 'circle'
children: [
{
name: 'sphere'
},
{
name: 'polygons'
}
]
},
{
name: 'triangle'
}
]
I have looked at aggregation extensively but can't seem to find a solution!
How can I exclude a value from being retrieved in an array of objects?
itemroot key of the document?