【发布时间】:2020-09-16 04:12:02
【问题描述】:
我有这个代码
User.findOne({ email: req.body.email }, function(err, user) {
if (user) {
return res.status(400).json([{ msg: 'The email address you have entered is already associated with another account.' }]);
}
user = new User({
name: req.body.name,
email: req.body.email,
password: req.body.password,
mobile: req.body.mobile
});
user.save(function(err) {
res.json({ token: generateToken(user), user: user });
});
});
我尝试使用邮递员发送请求,但我确实收到了用户对象的响应,这意味着保存功能中没有错误
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJleGNlcHRpb25zLnNnIiwic3ViIjoiNTc5NWQ0NzQxYmEzZWQwODE1ZTgzY2NmIiwiaWF0IjoxNDY5NDM3MDQ0LCJleHAiOjE0NzAwNDE4NDR9.2otkcPkJgsXvR8QOHAojDJ5YCxR7Uc2E4ApS77T55F8",
"user": {
"__v": 0,
"created_at": "2016-07-25T08:57:24.612Z",
"updated_at": "2016-07-25T08:57:24.612Z",
"name": "Test",
"email": "Test@hotmail.com",
"password": "$2a$10$3UmABiDPeo6iHZ.DFbwOO.1ANpUWQmwr86bYbTmRuFedsbDcE0bbC",
"mobile": 12345,
"_id": "5795d4741ba3ed0815e83ccf"
}
}
但是我的数据库中没有这个条目。我用 Robomongo 检查了我的数据库,我确定没有数据。我错过了什么?
【问题讨论】: