我在根级别的模式中有一个字段,并希望将其添加到数组中与条件匹配的每个对象中。
这是一个示例文档......
{
calls: [
{
"name": "sam",
"status": "scheduled"
},
{
"name": "tom",
"status": "cancelled"
},
{
"name": "bob",
"status": "scheduled"
},
],
"time": 1620095400000.0,
"call_id": "ABCABCABC"
}
Run Code Online (Sandbox Code Playgroud)
所需文件如下:
[
{
"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
}
]
Run Code Online (Sandbox Code Playgroud)
应将其call_id添加到数组中状态为“已计划”的所有对象。是否可以通过 mongo 聚合来做到这一点?我已经尝试过$addFields,但无法达到上述结果。提前致谢!