Various mongoose methods
- char.update()
- MarioChar.update()
- MarioChar.findOneAndUpdate()
// Saving the data
character = new MarioChar({
name: "Mario",
weight: 60
})
character.save().then(function(){
...
})
// Updating the data
MarioChar.findOneAndUpdate({ name:"Mario"}, { name:"new_name"}).then(function(){
MarioChar.findOne({ name:"Mario" }).then(result => {
...
})
})
The the new changes will be injected and this will not overwrite the complete objects. This update results to the object:
{ name: "new_name", weight: 100 }
and not just { name: "new_name" }
Top comments (0)