Mongodb Classroom image

Anil  Bist / Professional / DataBase

To post your Question Join Classroom
Lesson Topics's No:-  ||


Update the entire object:


Or just update a single field of a document. In this case age:

db.people.update ({name: 'Tom' }, {$set: {age: 29 } } )


You can also update multiple documents simultaneously by adding a third parameter. This query will update all documents where the name equals Tom:  


If a new field is coming for update, that field will be added to the document.

db.people.updateMany({name: 'Tom' },{$set:{age: 30, salary: 50000 } })// Document will have `salary` field as well.


If a document is needed to be replaced,

db.collection.replaceOne ( { name:'Tom' }, {name: 'Lakmal' ,age: 25 ,address: 'Sri Lanka' })  


can be used.

Note: Fields you use to identify the object will be saved in the updated document. Field that are not defined in the update section will be removed from the document.  

Anil  Bist

Skills    Mongodb

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a


  Students (0)