Mongodb Classroom image

Anil  Bist / Professional / DataBase

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2|
Lessons:-Update Operators

We lost Tom's age & name! From this example, we can know that the whole document will be overrided if without any update operator in update statement. This is the default behavior of MongoDB.

III.$set operator

If we want to change only the 'sex' field in Tom's document, we can use $set to specify which field(s) we want to update:

 

The value of $set is an object, its fields stands for those fields you want to update in the documents, and the values of these fields are the target values.

So, the result is correct now:

 

Also, if you want to change both 'sex' and 'age' at the same time, you can append them to $set :

 
 
 
image
Anil  Bist

Skills    Mongodb

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

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
Explore

 

  Students (0)