Home:ALL Converter>Update Query in MongoDB with where conditions

Update Query in MongoDB with where conditions

Ask Time:2013-01-30T21:33:05         Author:ArunKolhapur

Json Formatter

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

Above is my collection object.. I want to update which.name to "Indian" where which.status = 1.. Please help me with the mongoDB query for doing this..

Author:ArunKolhapur,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14605302/update-query-in-mongodb-with-where-conditions
Andy Refuerzo :

You can try this:\n\ndb.collection.update({\"whichs.status\" : \"1\" }, \n {$set : { \"whichs.$.name\" : \"Indian\"},\n false,\n true);\n\n\nThis finds \"whichs.status\" : \"1\" then sets \"whichs.$.name\" : \"Indian\" for all documents. For more info on the update() method, read here.",
2013-01-30T13:51:38
yy