I was writing mongoose middleware like so, using ES6:
userSchema.pre('save', (next) => {
// something...
next();
});
And that did not work. The middleware was invoked, but "this" did not refer to the document being saved. I then got rid of the lambda syntax:
userSchema.pre('save', function(next) {
// something...
next();
});
And it worked!
I've been happily using lambdas with Node for a while, does anyone know what the problem is? (I see there is a question about this issue here already, I would appreciate a fundamental answer, though).