我正在编辑配置文件页面,我想更改/更新我的mongooseDB中的文档信息,但我的代码不更新文档。有什么建议吗?
router.get('/edit', isAuthenticated, function (req, res, next) {
res.render('profile/editprofile', {
user: req.user
});
});
router.post('/edit', isAuthenticated, function (req, res, next) {
User.update({_id: req.session.passport.user.id}, {
email: req.body.email,
password: req.body.password,
name: req.body.name,
phone: req.body.phone,
classc: req.body.classc,
//graduated: req.body.graduated;
major: req.body.major,
minor: req.body.mino,
linkedin: req.body.linkedin,
bio: req.body.bio
}, function (err){
if (err) console.log(err);
res.render('profile/profile', {
user: req.user
});
});
});
答案 0 :(得分:1)
您忘记添加$set
运算符
router.post('/edit', isAuthenticated, function (req, res, next) {
console.log(req.user._id) //console like this
User.update({_id: req.user._id}, {$set: req.body}, function (err){
if (err) console.log(err);
res.render('profile/profile', {
user: req.user
});
});
});