Description
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
There is no way to run multiple validators on the shame field.
toySchema.path('name').validate(function(v) {
if (v !== 'Turbo Man') {
throw new Error('Need to get a Turbo Man for Christmas');
}
return true;
}, 'Name `{VALUE}` is not valid');
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
We should to be able to add multiple custom validators, and get back the result all of them.
I saw that there were some issue what reported the same, and the answer was, we can use mongoose-validator-all package. But that package have no more maintained for 1,5 years and anyway it should be supported by mongoose i think.
To prevent breaking changes, instead of overwrite the current validate system, just add a new one.
toySchema.path('password').validateMany([
function(v, f) {
if (this.name == v) {
return {
'passed': false,
'message': `field [${f}] can be the same as name, value: [${v}]`
};
}
return {
'passed': true,
};
},function(v, f) {
if (this.confirmPw == v) { //just for example
return {
'passed': false,
'message': `field [${f}] have to be the same as password, confirmPw, password: [${this.confirmPw}, ${v}]`
};
}
return {
'passed': true,
};
},
]);
Errors:
{
"password": [{error Object}, {error Object}]
}
UI:
For be able to compare fields whit others e.g password, this should to contain the document itself as in pre hooks.