【发布时间】:2021-10-01 10:34:24
【问题描述】:
我有这个收藏:
{
"_id": ObjectId("6045eec8f113547ddd3472d9"),
"execution": {
"_id": ObjectId("6045eec8f113547ddd3472d8"),
"steps": [
{
"_id": ObjectId("6045eec8f113547ddd3472d7"),
"actions": [
{
"_id": ObjectId("6045eec8f113547ddd3472d6"),
"title": "action title"
}
]
}
]
}
}
我想达到这个结果:
{
"_id": ObjectId("6045eec8f113547ddd3472d9"),
"allActions": [
{
"_id": ObjectId("6045eec8f113547ddd3472d6"),
"title": "action title"
}
]
}
为了澄清更多,我想添加一个数组,将“步骤”数组下的所有“动作”组合在一起
db.getCollection("missions").aggregate([
{
$match: {
_id: ObjectId("6045eec8f113547ddd3472d9")
}
},
{
$addFields: {
"allActions": "$execution.steps"
}
}
])
有人可以帮我完成代码部分,让我获得所需的输出吗?
【问题讨论】:
标签: mongodb mongodb-query aggregation-framework