Last active
May 26, 2020 16:44
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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