Sunday, 7 May 2017

Mongoose schema.post events broken in versions >= 4.8.0

In a node app that uses mongoose, I defined some mongoose middleware hooks like this:

mongoose.model('MyModel').schema.post('save', function(document) {
    // following is executed in 4.7.9 but not 4.8.0
    console.log('saved');
});

These work perfectly well in mongoose versions up to and including 4.7.9 but if I update mongoose to 4.8.0 in my application, then with no other changes, these hooks fail to be invoked at all. There are no warnings or errors.

http://mongoosejs.com/docs/middleware.html suggests that the way to define these hooks hasn't changed. Is there something different I need to do in 4.8.0+ to retain this behaviour?



via darrend

No comments:

Post a Comment