MongoDB Update Document-Programmershelper



This article will provide step by step basic concept of MongoDB. where you can easily understand the core concept of MongoDB.The following method <db.collection.update> is used to update a existing document in the collection. you just define criteria for the update and only selected document will update.


It would be better if you have the basic knowledge of RDBMS concept. Actually, you are going to learn a high-performance database.It will good to cover my below articles before this.Its help to learn more about MongoDB.In which I explained.Click here Insert a document in MongoDB and Find a document in MongoDB.

Implementation Section

Using update method()  you will updates a single value and update the whole document its depending on your requirement.

  • MongoDB update Method().


Simple syntax to update a document is following-


db.students.update({‘name’:‘Programmershelper’}, { $set:{‘age’: 20 } } )

  • <db> is a reserved word.
  • <Collection_name> writes the collection name.
  • <Update> is also reserverd word used for Update the existing record in collection.
  • Inside the bracket write the document <specific_criteria and Update data>.

The Following example I will set the name<new programmershelpes MongoDB tutorial> of the documents whose name is <programmaerhelper>.

You do not confuse MongoDB update document.I configure MongoDB command prompt shell into IntelliJ IDEA.Next post I will show details how to configure it.

Alt tagMongoDB update document

I simply used find query using find method () to fetch data from a database.then I updated a field in a document.


Alt tag MongoDB update document

By default, you will updates a single record in MongoDB.But if you want to update more than one record you need to set parameter <multi to true>.


I wish I could tell you that a great site of just understands key element above post. for detail how to MongoDB update document How can update the document in also read my previous lecture.I hope you will understand this lecture.Thank you for reading this lecture. Hope you got the idea.