Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Mongoose Schema.pre(';save';)函数不散列我最新更新的密码_Javascript_Node.js_Express_Mongoose_Mongoose Schema - Fatal编程技术网

Javascript Mongoose Schema.pre(';save';)函数不散列我最新更新的密码

Javascript Mongoose Schema.pre(';save';)函数不散列我最新更新的密码,javascript,node.js,express,mongoose,mongoose-schema,Javascript,Node.js,Express,Mongoose,Mongoose Schema,我正在尝试更新控制器中的用户密码,但在运行.save() 这是我控制器中的代码 const user = await User.findById(token.user_id); user.password = password; await user.save(); 这是我的.pre()函数 UserSchema.pre('save', async function (next) { console.log('we ran .save()'); // this console.log()

我正在尝试更新控制器中的用户密码,但在运行
.save()

这是我控制器中的代码

const user = await User.findById(token.user_id);
user.password = password;
await user.save();
这是我的
.pre()
函数

UserSchema.pre('save', async function (next) {
  console.log('we ran .save()'); // this console.log() displayed
  try {
    if (this.password && this.isModified('password')) {
      this.password = await bcrypt.hash(this.password, passwordSaltRound);
      console.log('we got here', this.password); // this didn't
    }
    next();
  } catch (err) {
    next(err);
  }
});  
正如您在控制台日志中看到的,它运行了
.pre()
,但没有输入条件。
:(

无法复制此信息-新密码是否与旧密码不同?如果值相同,则修改后的密码将返回false。