gpt4 book ai didi

node.js - 更新用户信息 mongoose, MongoDB, NodeJS

转载 作者:可可西里 更新时间:2023-11-01 10:39:04 24 4
gpt4 key购买 nike

我正在编辑个人资料页面,我想更改/更新我的 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
});
});
});

最佳答案

你忘了添加$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
});
});
});

关于node.js - 更新用户信息 mongoose, MongoDB, NodeJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50431619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com