在具有where条件的MongoDB中更新查询

时间:2013-01-30 13:33:06

标签: mongodb

{
"_id" : ObjectId("510902fb7995fe3504000002"),
"name" : "Gym",
"status" : "1",
"whichs" : [
    {
        "name" : "American",
        "status" : "1"
    }
]
}

上面是我的集合对象..我想将which.name更新为“Indian”,其中which.status = 1 ..请帮我处理mongoDB查询。

1 个答案:

答案 0 :(得分:0)

你可以试试这个:

db.collection.update({"whichs.status" : "1" }, 
                     {$set : { "whichs.$.name" : "Indian"},
                     false,
                     true);

这会找到"whichs.status" : "1"然后为所有文档设置"whichs.$.name" : "Indian"。有关update()方法的更多信息,请阅读here

相关问题