Complete the code to add a pre-save hook that logs a message before saving a document.
schema.pre('save', function(next) { console.log('About to save document'); [1](); });
The next function must be called to continue the middleware chain in Mongoose pre hooks.
Complete the code to add a post-save hook that logs the saved document.
schema.post('save', function(doc) { console.log('Document saved:', [1]); });
this instead of the passed document in post hooks.In post-save hooks, the saved document is passed as the first argument, commonly named doc.
Fix the error in the pre-remove hook to properly call the next middleware.
schema.pre('remove', function([1]) { console.log('Removing document'); next(); });
The middleware function must declare next as a parameter to call it properly.
Fill both blanks to create a pre-find hook that modifies the query to only find active users.
schema.pre('[1]', function() { this.[2]({ active: true }); });
The pre-find hook runs before a find query. The this context is the query, so calling this.where() modifies the query conditions.
Fill all three blanks to create a post-update hook that logs the update result and calls next.
schema.post('[1]', function(result, [2]) { console.log('Update result:', [3]); next(); });
The post-update hook listens to 'updateOne'. The second parameter is the next callback. The first parameter is the update result.