【发布时间】:2016-02-03 15:58:34
【问题描述】:
我有一个包含对象的数组。
这些对象有名称和颜色。有些对象还可以包含子对象! (其他对象的数组)。
{
items : [
{
name: 'box'
color: 'red'
},
{
name: 'circle'
color: 'blue'
children: [
{
name: 'sphere'
color: 'orange'
},
{
name: 'polygons'
color: 'green'
}
]
},
{
name: 'triangle'
color: 'pink'
}
]
}
我需要检索这些项目的所有名称并排除它们的颜色。
结果应该是:
items : [
{
name: 'box'
},
{
name: 'circle'
children: [
{
name: 'sphere'
},
{
name: 'polygons'
}
]
},
{
name: 'triangle'
}
]
我已经广泛研究了聚合,但似乎找不到解决方案!
如何排除在对象数组中检索的值?
【问题讨论】:
-
是
item文档的根键吗? -
是的。 { items : [ .. ] } - 我刚刚编辑了问题以使其更清楚。
标签: arrays mongodb mongodb-query