How to update a record in mongo db by "_id"

If you want to update a record in mongo db by "_id". Suppose below is a collection(table) with name "ceo" . So now you want to update name "Karm Khanna" with "Salman Ahmad"


Update a record in mongo db by "_id"


So now the update query will be like below :


db.ceo.update({"_id": ObjectId("56ab0b7fac34b55d1aa2b515") }, { $set: {"name": "salman ahmad"}});





Chears 
Happy coding :)

Post a Comment

Previous Post Next Post