我正在尝试更新mongodb集合文档,我需要将最新值更新为“0”,只有其值为“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",
}
]
}
查询:
db.test.update({"_id" : ObjectId("56411fda7f8b9a4503adeb1e"),'campaigns.latest' : 1},{'$set':{"campaigns.$.latest":0}},{'multi':true});
它只更新第一场比赛而不是全部,请任何人帮助我们解决。