Guest User

Untitled

a guest
Aug 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. MongoDB: how to update embeded documents in array
  2. {_id: '4eb79ee1e60fc603788e7259',
  3. Name: 'name',
  4. Subsidiaries: [
  5. { _id: '4eb79eeae60fc603788e7271',
  6. Location: 'location1'},
  7. { _id: 'subid2',
  8. Location: 'location2'},
  9. ]}
  10.  
  11. db.Departments.update({ "_id" : ObjectId("4eb79ee1e60fc603788e7259"), "Subsidiaries._id" : ObjectId("4eb79eeae60fc603788e7271") }, { "$set" : { "Subsidiaries.Location" : "City" } })
  12.  
  13. db.Departments.update({ "_id" : ObjectId("4eb79ee1e60fc603788e7259"), "Subsidiaries._id" : ObjectId("4eb79eeae60fc603788e7271") }, { "$set" : { "Subsidiaries.$.Location" : "City" } })
Add Comment
Please, Sign In to add comment