Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MongoDB: how to update embeded documents in array
- {_id: '4eb79ee1e60fc603788e7259',
- Name: 'name',
- Subsidiaries: [
- { _id: '4eb79eeae60fc603788e7271',
- Location: 'location1'},
- { _id: 'subid2',
- Location: 'location2'},
- ]}
- db.Departments.update({ "_id" : ObjectId("4eb79ee1e60fc603788e7259"), "Subsidiaries._id" : ObjectId("4eb79eeae60fc603788e7271") }, { "$set" : { "Subsidiaries.Location" : "City" } })
- db.Departments.update({ "_id" : ObjectId("4eb79ee1e60fc603788e7259"), "Subsidiaries._id" : ObjectId("4eb79eeae60fc603788e7271") }, { "$set" : { "Subsidiaries.$.Location" : "City" } })
Add Comment
Please, Sign In to add comment