I\'m trying to decide how I want to handle validation errors in Mongoose.
I have defined my own validation rules
As of mongoose 4.5.0 Document#invalidate returns a ValidationError. See this https://github.com/Automattic/mongoose/issues/3964
Also, when trying to invalidate on a findOneAndUpdate query hook, you can do:
// pass null because there is no document instance
let err = new ValidationError(null)
err.errors[path] = new ValidatorError({
path: 'postalCode',
message: 'postalCode not supported on zones',
type: 'notvalid',
value,
})
throw(err)