title: Best way to check for mongoose validation error
body: <p>I've got two <a href="http://mongoosejs.com/docs/validation.html">validation</a> functions for my usermodel</p>
  
  <pre><code>User.schema.path('email').validate(function(value, respond) {
    User.findOne({email: value}, function(err, user) {
      if(err) throw err;
      if(user) return respond(false);
      respond(true);
    });
  }, 'EMAIL_EXISTS');
  </code></pre>
  
  <p>and the same for <code>username</code></p>
  
  <pre><code>User.schema.path('username').validate(function(value, respond) {
    User.findOne({username: value}, function(err, user) {
      if(err) throw err;
      if(user) return respond(false);
      respond(true);
    });
  }, 'USERNAME_TAKEN');
  </code></pre>
  
  <p>They return errors in the following format</p>
  
  <pre><code>{ message: 'Validation failed',
    name: 'ValidationError',
    errors: 
      { username: 
        { message: 'Validator "USERNAME_TAKEN" failed for path username',
          name: 'ValidatorError',
          path: 'username',
          type: 'USERNAME_TAKEN' } } }
  </code></pre>
  
  <p>The error for the <code>email</code> path is similar. Is there a smarter way to check for those errors than the following?</p>
  
  <pre><code>if (err &amp;&amp; err.errors &amp;&amp; err.errors.username) { ... }
  </code></pre>
  
  <p>This is kind of ugly.</p>