I am getting this error in the pre findOneAndupdate Hook up
uncaughtException: Cannot read property 'update' of undefined
Middleware hook up code:
purchaseSchema.pre('findOneAndUpdate', function (next) {
this.model.findOne(this._conditions)
.then(purchaseOrder => {
if (!this._update.is_draft && (!this._update.code && !purchaseOrder.code)) {
codeSequence('PurchaseSchema', 'purchaseOrders', 'FC', function (err, sequence) {
if (err) {
new Error("Error al generar secuencia: ", err.message);
} else {
this.update({}, {
$set: {
code: sequence
}
})
next();
}
});
} else {
next();
}
})
.catch(err => next(err));
});
I am using mongoose 4.13.5 I don't understand why I am getting this error now