When I am running this code :
const mongoose = require('mongoose');
const ASchema = mongoose.Schema({
test: {
type: String
},
});
ASchema.pre('validate', function (next) {
console.log('pre validate')
console.log(this);
next();
});
ASchema.pre('save', function (next) {
console.log('pre save, not run')
next();
});
const AModel = mongoose.model('test', ASchema);
const a = new AModel({
test: { value: '1' }
});
await a.save();
I am getting as output :
pre validate
{ _id: new ObjectId("61c9f38e3f8f3d783d0e83c1") }
I was expecting to get :
pre validate
{ _id: new ObjectId("61c9f38e3f8f3d783d0e83c1"), test: { value: '1' } }
I want to get the test field in pre('validate') function even if it's not valid so I can process it. Is that possible ?