I'm trying to update the mongodb collection document, I need to update the value of latest to "0" only its values is "1"
{
"_id" : ObjectId("56411fda7f8b9a4503adeb1e"),
"campaigns" : [
{
"latest" : NumberInt (0),
"timestamp" : "2015-11-10 00:16:10",
"name" : "camp1",
},
{
"latest" : NumberInt(1),
"timestamp" : "2015-11-11 00:16:10",
"name" : "camp2",
},
{
"latest" : NumberInt(1),
"timestamp" : "2015-11-12 00:16:10",
"name" : "camp3",
}
]
}
Query :
db.test.update({"_id" : ObjectId("56411fda7f8b9a4503adeb1e"),'campaigns.latest' : 1},{'$set':{"campaigns.$.latest":0}},{'multi':true});
it updates only the first matches not all, Please can anyone help us to solve.