I have a custom scheme where I want to update some information, for example.
User.findOne({_id: idd}, function(err, usr){
usr.info = "some new info";
usr.save(function(err) {
});
});
But the model has a hook for saving to a hash password
UserSchema.pre('save', function(next) {
if (this.password && this.password.length > 6) {
this.salt = new Buffer(crypto.randomBytes(16).toString('base64'), 'base64');
this.password = this.hashPassword(this.password);
}
next();
});
Now, when I try to save, it accepts allready hased password and hash it again, any idea how to avoid this?
source
share