2017-10-17 12 views
0

mongooseを使用してフォーム入力を含むユーザーのドキュメントを更新したいとします。ユーザー文書の内部では、個人情報セクション(この場合はfullNameプロパティ)にアクセスしてフォームのデータで更新したいと思います。私はmongoose update関数でpersonalInfo.fullNameを試しましたが、これはうまくいかないようです。誰でもこれを修正できますか?mongoose(ドキュメントプロパティの更新プロパティ)を使用してドキュメントを更新する

Here is an example of a user document

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") 
    }) 
}); 

答えて

1

を中心に "personalInfo.fullName"を引用符を追加してみてください:

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") 
}) 
関連する問題