I\'m trying to decide how I want to handle validation errors in Mongoose.
I have defined my own validation rules
Warning: As of Mongoose 4.1.3 the signature for function ValidatorError has completely changed and the information below is no more applicable:
As of Mongoose 3.8.12 the signature for function ValidatorError is:
function ValidatorError (path, msg, type, val)
Where type can be either "notvalid" or "required"
For example if your "email" field validation raises a validation error, you can simply do:
var error = new ValidationError(this);
error.errors.email =
new ValidatorError('email', "Your err message.", 'notvalid', this.email);