Reputation: 105
I would like to update the document of a user with form inputs using mongoose. Inside the user document I would like to access the personal info section (and in this case its fullName property) to update it with the form's data. I tried with personalInfo.fullName in the mongoose update function, but this doesn't seem to work. Can anyone fix this?
router.post('/personalInfo', function (req, res, next) {
User.update({username: req.user.username}, {$set: { personalInfo.fullName: req.body.fullName}}, function (err, user) {
if (err) throw error
console.log(user);
console.log("update user complete")
})
});
Upvotes: 2
Views: 6841
Reputation: 12071
Try adding quotes around "personalInfo.fullName":
User.update({
username: req.user.username
}, {
$set: {
"personalInfo.fullName": req.body.fullName
}
}, function (err, user) {
if (err) throw err
console.log(user)
console.log("update user complete")
})
Upvotes: 4