In various tutorials, I have come across this particular example and it has raised a question in my mind. I am curious as to why this works with new documents. Could it be that new documents are automatically considered modified? Wouldn't it make more sense to 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);
}
});