小编Bar*_*ter的帖子

属性“密码”在文档类型上不存在

我收到此错误文档类型上不存在属性“密码”。那么谁能说出我的代码是否有问题?

const userSchema = new mongoose.Schema({
  email: { type: String, required: true, unique: true },
  password: { type: String, required: true },
  name: { type: String, required: true }
});

userSchema.pre("save", function save(next) {
  const user = this;
  if (!user.isModified("password")) {
    return next();
  }
  bcrypt.genSalt(10, (err, salt) => {
    if (err) {
      return next(err);
    }
    bcrypt.hash(user.password, salt, (err: mongoose.Error, hash) => {
      if (err) {
        return next(err);
      }
      user.password = hash;
      next();
    });
  });
});
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

bcrypt mongoose typescript

4
推荐指数
3
解决办法
924
查看次数

标签 统计

bcrypt ×1

mongoose ×1

typescript ×1