Skip to content

Commit

Permalink
Update middlewar.pug file
Browse files Browse the repository at this point in the history
the documentation does not specificly addresses that both properties 'query' and 'document' must be assigned in order for the 'remove' middleware to execute for the right context (that is on the query or the document).
  • Loading branch information
mustafaKamal-fe authored Nov 8, 2020
1 parent 8b0e869 commit b9553b6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/middleware.pug
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,17 @@ block content
You can pass options to [`Schema.pre()`](/docs/api.html#schema_Schema-pre)
and [`Schema.post()`](/docs/api.html#schema_Schema-post) to switch whether
Mongoose calls your `remove()` hook for [`Document.remove()`](/docs/api.html#model_Model-remove)
or [`Model.remove()`](/docs/api.html#model_Model.remove):
or [`Model.remove()`](/docs/api.html#model_Model.remove). Note here that you need to set both `document` and `query` properties in the passed object:

```javascript
// Only document middleware
schema.pre('remove', { document: true }, function() {
schema.pre('remove', { document: true, query: false}, function() {
console.log('Removing doc!');
});

// Only query middleware. This will get called when you do `Model.remove()`
// but not `doc.remove()`.
schema.pre('remove', { query: true }, function() {
schema.pre('remove', { query: true, document: flse }, function() {
console.log('Removing!');
});
```
Expand Down

0 comments on commit b9553b6

Please sign in to comment.