I have a user document
username: "Ralph",
email: "[email protected]",
resetPasswordToken: null,
resetPasswordExpires: null
and I want to update the resetPasswordToken and the resetPasswordExpires properties in an Express route,
I did this :
router.post("/forgotPassword", (req, res) => {
User.findOne({ email: req.body.email }).then(user => {
if (user === null) {
console.log("NO user with this mail exists");
} else {
console.log("user with this mail exists");
const token = crypto.randomBytes(20).toString("hex");
const myDate = new Date();
const newDate = new Date(myDate);
user.update({
resetPasswordToken: token,
resetPasswordExpires: newDate.setHours(newDate.getHours() + 1)
});
I see the log "user with this mail exists" in the terminal, but the user.update is never done, because there are no changes in my MongoDB database,
Does someone have a solution ? Thanks