【发布时间】:2021-07-26 19:52:02
【问题描述】:
我在根级别的架构中有一个字段,并希望将其添加到数组中与条件匹配的每个对象中。
这是一个示例文档....
{
calls: [
{
"name": "sam",
"status": "scheduled"
},
{
"name": "tom",
"status": "cancelled"
},
{
"name": "bob",
"status": "scheduled"
},
],
"time": 1620095400000.0,
"call_id": "ABCABCABC"
}
所需文件如下:
[
{
"call_id": "ABCABCABC",
"calls": [
{
"call_id": "ABCABCABC",
"name": "sam",
"status": "scheduled"
},
{
"name": "tom",
"status": "cancelled"
},
{
"call_id": "ABCABCABC",
"name": "bob",
"status": "scheduled"
}
],
"time": 1.6200954e+12
}
]
call_id 应添加到数组中状态为“已调度”的所有对象。
是否可以使用 mongo 聚合来做到这一点?我试过$addFields,但无法达到上述结果。
提前致谢!
【问题讨论】:
标签: mongodb aggregation