我有以下文档结构
{
assets : {
type : [
{
type : spread
scene : [
{
....
},
{
....
}
]
}
]
}
}
所以我想在同一文档中的"场景"数组中添加匹配条件为"spread"类型的新元素
如何为相同的代码编写 Mongo 更新查询?
下面是示例数组
{
assets : {
type : [
{
type : spread
scene : [
{
....
},
{
....
}
]
}
]
}
}
参考链接MongoDB 和 Meteor - 推送到嵌套数组的查询不起作用,没有抛出错误
并在场景数组中插入新元素的查询是
db.PhotostoryDesigner.update(
{
"photostoryId":"123",
"assets.type.type":"spreads"
},
{"$push": {
'assets.type.$.scene':{"$each":[
{
"scene_id": "1",
"name": "Ad hoc 1",
"spread": [
{
"spreadId": "7725",
"name": "PAGE 1-2",
"asset": []
}
]
}
]}}
}
);