Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nguyenphuongduy124/cee9b365d9cc3e2d88ee25437c988721 to your computer and use it in GitHub Desktop.
Save nguyenphuongduy124/cee9b365d9cc3e2d88ee25437c988721 to your computer and use it in GitHub Desktop.
MongoDB and Mongoose - Thực hiện update bằng cách Find, Edit và Save
var findEditThenSave = function(personId, done) {
var foodToAdd = "hamburger";
Person.findById(personId, function(err, data){
if(err) return done(err);
data.favoriteFoods.push(foodToAdd);
data.save(function(errSave, data){
if(errSave) return done(errSave);
done(null, data)
});
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment