mongoose.save() does not save it's data mongoose.save() does not save it's data mongoose mongoose

mongoose.save() does not save it's data


I think that the problem is in your pre save middleware. If you look carefuly, next() only gets triggered if your updates include the password. If your update object doesn't include that field, the middleware will prevent the save method to be finally implemented, as next() was never called.You can check if this is the problem quite quickly, just by adding next() also for the updates that don't involve the password:

userSchema.pre<UserBaseDocumentType>("save", function (next) { let user = this; if (user.isModified("password")) {   bcrypt.genSalt(saultRounds, function (err, salt) {     if (err) return next(err);     bcrypt.hash(user.password, salt, function (err, hash) {       if (err) return next(err);       user.password = hash;       next();     });   }); } next();});