I have seen this example in different tutorials and I just wonder why this works with new documents. Are new documents considered modified? Shouldn't we use this.isNew || this.isModified instead of just isModified?
try {
if (!this.isModified("password")) {
return next();
}
let hashedPassword = await bcrypt.hash(this.password, 10);
this.password = hashedPassword;
return next();
} catch (err) {
return next(err);
}
});