Closed alexcagliari87 closed 4 years ago
You could just create a field inside the global scope like:
bookSchema.pre('validate', async function () {
this.test = Object.assign({},this._doc);
...
this.test.field = 'abc';
...
});
Also check out the other issue you opened, you seem to not respond anymore to your issues.
@Ncifra 's solution is correct, although you should use the $locals
property instead
this.$locals.test = Object.assign({}, this._doc);
Also, why are you copying the document and what do you mean by "passing my 'test' object to validate"?
Hi all,
i have a problem using the pre validate hook in a mongoose model.
What i want is to "overwrite" in the pre-validate hook the data that will bepassed to validation and post-validate .
My code is:
I need to pass my "test" object to validate and post validate method...I didn't find anything in documentation...
I need to overwrite passed data....How can i do?