我有一个深层嵌套的文档结构,如下所示:
{id: 1,
forecasts: [ {
forecast_id: 123,
name: "Forecast 1",
levels: [
{ level: "proven",
configs: [
{
config: "Custom 1",
variables: [{ x: 1, y:2, z:3}]
},
{
config: "Custom 2",
variables: [{ x: 10, y:20, z:30}]
},
]
},
{ level: "likely",
configs: [
{
config: "Custom 1",
variables: [{ x: 1, y:2, z:3}]
},
{
config: "Custom 2",
variables: [{ x: 10, y:20, z:30}]
},
]
}
]
},
]
}
我正在尝试更新集合以插入新的配置,如下所示:
newdata = {
config: "Custom 1",
variables: [{ x: 111, y:2222, z:3333}]
}
我正在mongo中尝试这样的事情(在Python中):
db.myCollection.update({"id": 1,
"forecasts.forecast-id": 123,
"forecasts.levels.level": "proven",
"forecasts.levels.configs.config": "Custom 1"
},
{"$set": {"forecasts.$.levels.$.configs.$": newData}}
)
我收到“无法在没有包含数组的相应查询字段的情况下应用位置运算符”错误。在mongo中执行此操作的正确方法是什么?这是mongo v2.4.1。
温温酱
相关分类