【发布时间】:2018-12-22 17:10:07
【问题描述】:
我想使用名为token 的字段发布请求。这是我的猫鼬模式
const UserSchema = mongoose.Schema({
name: {
type: String
},
email: {
type: String,
required: true,
unique: true
},
username: {
type: String,
required: true,
unique: true
},
password: {
type: String,
required: true
},
phone: {
type: String
},
resetPasswordToken: {
type: String
},
resetPasswordExpires: {
type: Date
}
});
这是我来自user.js的路线文件
router.put('/reset/:token', function(req, res) {
console.log('listening');
User.findOneAndUpdate(
{resetPasswordToken:req.params.token},
{
password: req.body.password,
resetPasswordToken: undefined,
resetPasswordExpires: undefined
},
function(err,user) {
if(err) {
console.log(err + 'is here');
} else {
res.json(user);
}
}
);
});
这是我发送 `POST 请求的地方。
resetPassword(passwordData) {
let headers = new Headers();
console.log(passwordData);
headers.append('Content-Type','application/json');
return this.http.put('http://localhost:3000/api/reset/'+passwordData.token,passwordData,{headers: headers})
.map(res => res.json());
}
没有采取任何行动我无法在我的 cmd 中看到 listening。对于用户,我已经将令牌值设为
"resetPasswordToken" : "2a287acacf7d5e98de9a158c8be82744ef0302f9"
我可以使用邮递员进行更新,但无法使用代码进行更新。
【问题讨论】:
标签: node.js mongodb express mongoose mean-stack