Why I couldn't user arrow function?

Hello, I’m making a pre-hook using mongoose. When I made it like this:

articleSchema.pre('validate', (next) => {
    console.log(this)
    next()
})

it was not working (this was not pointing on the object that I was creating), but when I changed it from arrow function to regular function expression:

articleSchema.pre('validate', function(next) {
    console.log(this)

    next()
})

it started working. Why is that happening and why I couldn’t user an arrow function?

Hello there.

I believe it has to do with this Q&A on https://mongoosejs.com/docs/faq.html:

Q . I’m using an arrow function for a virtual, middleware, getter/setter, or method and the value of this is wrong.

A . Arrow functions handle the this keyword much differently than conventional functions. Mongoose getters/setters depend on this to give you access to the document that you’re writing to, but this functionality does not work with arrow functions. Do not use arrow functions for mongoose getters/setters unless do not intend to access the document in the getter/setter.

Hope this helps