Mongodb Classroom image

Anil  Bist / Professional / DataBase
 
To post your Question Join Classroom
 
Lesson Topics's No:-  ||
Lessons:-Update

Update

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.  

 
 
 
image
Anil  Bist

Skills    Mongodb

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

in 2006, i Join a web development company in Bangalore and start work on "Ruby on Rail" this is my first web development framework and we worked in this framework and develop four to five project after some time , I moved to JEE/Sturst frame work,

After some time i decided that now times come and I have to go on in my own way and I started a company name is "Soarlogic&q
Explore

 

  Students (0)