我正在尝试更新 mongodb 中的嵌套子文档,
{
id: 100,
status: [ {
campaigns: [
{ timestamp: "2014-07-30",
task: [
{
id: "1",
created: "2014-07-30"
}
]
},
{ timestamp: "2014-07-31",
task: [
{
id: "2",
created: "2014-07-31" // need to update this field
}
]
},
]
},
]
}
更新查询
db.collectionname.update({"id": 100,"status.campaigns.task.id":"2"},{$set:{"status.0.campaigns.$.task.created:"2014-08-01"}});
上面的查询只更新第一条记录(task.id = "1" 创建日期)它不更新 task.id="2" 子文档!!!!