I am trying to update nested subdocument in 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
}
]
},
]
},
]
}
Update Query
db.collectionname.update({"id": 100,"status.campaigns.task.id":"2"},{$set:{"status.0.campaigns.$.task.created:"2014-08-01"}});
the above query updates only first record (task.id = "1" created date) its not updating task.id="2" subdocument!!!!