Trying to retrieve all validation errors #1104

silently opened this Issue Sep 12, 2012 · 4 comments

2 participants



Let's say I want to validate several conditions on a given path:
User.schema.path('password').validate(function (value) { ... }, 'error1');
User.schema.path('password').validate(function (value) { ... }, 'error2');

When I save a document that fails on both conditions like this: {..})

I have two problems:

  • err only contains 'error1'
  • 'error2' is not caught by the callback and then appears in the node process: "No listeners detected, throwing. Consider adding an error listener to your connection"

Is there a way to ask mongoose not to call User#save callback until all validations are tested?



Hello Aaron,

I cannot reproduce the error2 not being caught, I don't know what happened when I noticed it, so ok it's not a bug. I have done this little gist to test it :

But I think retrieving all validation errors can be expected in some scenarios.

Let's say mongoose validation is the root logic for form-posted data on a website I am trying to register on:

  • I choose the password "test" > error returned : password too short
  • then I submit "testtest" as the password > error returned : password should contain at least one digit (just an example)

There are many similar use cases, what is your opinion about that ?



yep. duplicate of #1031

@aheckmann aheckmann closed this Sep 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment