mongoose.Schema.isModified is not a function

Viewed 22

'user.isModified is not a function. I keep getting the same error message. And I have no clue where to start tackling the issue.

  userSchema.pre('updateOne', function(next) {
  const user = this;
  
  if (!user.isModified('password')) return next(); 

  bcrypt.genSalt((error, salt) => {
    if (error) return next(error); 
    
    bcrypt.hash(user.password, salt, (error, hash) => {
      if (error) return next(error); 
  
      user.password = hash; 
      next();
    }) 
  })
})
1 Answers

i believe user is undefined can you try it with userSchema.post

Related