Difference between revisions of "MongoDB Update"

From mi-linux
Jump to navigationJump to search
(Created page with "Main Page >> MongoDB >>MongoDB Workbook >> Updating Collections == Updating a Collection == To add an employee to department 40: db.de...")
 
Line 19: Line 19:
 
   }
 
   }
 
  )
 
  )
 +
 +
Change the location to Wolverhampton:
 +
 +
db.deptCollection.update({'deptno':40},
 +
  {$set:  {'loc': 'WOLVERHAMPTON'}})
 +
 +
Check the changes have been made:
 +
 +
db.deptCollection.find({"deptno":40}).pretty()

Revision as of 22:35, 18 October 2016

Main Page >> MongoDB >>MongoDB Workbook >> Updating Collections

Updating a Collection

To add an employee to department 40:

db.deptCollection.update({'deptno':40}, 
 {$set: 
   {'employees': [   
     {
      empno: 8888,
      ename: 'MARY',
      job: 'LECTURER',
      mgr: 7566,
      hiredate: new Date(),
      sal: 4000
     } 
   ]}
 }
)

Change the location to Wolverhampton:

db.deptCollection.update({'deptno':40}, 
 {$set:  {'loc': 'WOLVERHAMPTON'}})

Check the changes have been made:

db.deptCollection.find({"deptno":40}).pretty()