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 plete")
})
});
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 plete")
})
});
Share
Improve this question
asked Oct 17, 2017 at 16:15
Tijl DeclerckTijl Declerck
1052 silver badges11 bronze badges
1 Answer
Reset to default 4Try 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 plete")
})
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745364074a4624494.html
评论列表(0条)