A bold arrow ( => ) is not useful in this situation. Instead, just use the deprecated anonymous function:
UserSchema.pre('save', function(next) { ... });
The reason is that the bold arrow lexically binds the function to the current scale (more on this here , but TL; DR: the designation of the bold arrow does not mean to be a generalized musical notation, it meant specifically to create lexically related functions), whereas the function should be called in the area provided by Mongoose.
robertklep
source share