title: Mongoose validate length of array in schema
body: <p>I want to create a schema, with arrays for names of participants at an event, I make the list of participants by doing so:</p>
  <pre><code>  quizPart:[{
      type:String,
    }]
  </code></pre>
  <p>How can I validate that the length of this array is either zero (no participants at this event) or 2, and not 1 (it is a two people per team event). I want to return an error message that I can handle with  <code>ValidationError</code></p>
  <p>I am adding data to this schema like so:</p>
  <pre><code>var school = new School();
  school.quizPart=req.body.quiz;
  </code></pre>
  <p>where <code>req.body.quiz = [&quot;name1&quot;,&quot;name2&quot;]</code> or <code>['','']</code></p>
  <p>and then, if only 1 field has a string value, I want to parse an error to the repsonse body like so:</p>
  <pre><code>    function handleValidationError(err, body) {
        for (field in err.errors) {
          switch (err.errors[field].path) {
            case &quot;quizPart&quot;:
              body[&quot;quizPartError&quot;] = err.errors[field].message;
              break; 
  }}}
  </code></pre>