MongoDB

Replace a document using Mongo Shell

The following operation replaces the document with item equal to “Himen Patel”. The newly replaced document will only contain the the _id field and the fields in the replacement document.

 > db.users.update(  
... { Name : "Himen Patel" },
... {
... "Name": "Himen Paatel",
... "Email": "email2himen@dotnet-funda.com",
... "Address1": "1257 Commons Drive",
... "City": "Cooperstown",
... "Zip Code": "13326",
... "Country": "USA"
... }
... )

A successful update of the document returns the following object.

 WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })  

Leave a comment