Automattic / Automattic/mongoose
Pass doc as parameter to pre and post hooks
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 32
Description
It would be handy to have the document itself available as an parameter passed to the function rather than the this context so we can use arrow functions rather than the long form syntax.
Sort of like this
```js
UserSchema.pre('save', (next, doc) => {
doc.password = await hash(doc.password)
next()
})
```
Contributor guide
Research direction
Start by tracing the UserSchema.pre('save') hook API and the corresponding pre and post middleware behavior. Confirm the intended callback argument order and how arrow functions should receive the document, then add coverage for both hook types. Done means the document is available as a function argument without relying on this.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb, node.js
- Domain
- backend, databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100