title: Execute query in Mongoose schema validation
body: <p>Im trying to setup my MongoDB design in such a way that there is a <code>projects</code> collection, and a <code>people</code> collection. The <code>Project</code> model schema contains a <code>_people</code> item, which references the <code>People</code> model. (As opposed to the People model having a field to reference the project he/she belongs to. It needs to be like this)</p>
  
  <p>I need to run a validation whenever a new document is created in the <code>people</code> container, that there can be only one manager per a project. This would be very easy if it was possible for me to execute a query for the elements validation in the schema, but I don't believe thats possible...</p>
  
  <p>Heres the schema for the <code>People</code> model currently:</p>
  
  <pre class="lang-js prettyprint-override"><code>const peopleSchema = new Schema( {
      name: {
          type: Schema.Types.String,
          required: true,
          minlength: 3,
          maxlength: 25,
          trim: true,
          select: true
      },
      isManager: {
          type: Schema.Types.Boolean,
          default: false,
          validate: {
              validator: function ( v ) {
                  // How can I check if there are any existing `people` documents with the 
                  // `isManager` set to true, which are referenced by the same project.
                  // If I can return a promise from here, then I can just execute a query and verify the results
              },
              message: 'There can be only one manager per each group'
          }
      }
  })
  </code></pre>
  
  <p>As you can see in the <code>isManager.validate.validator</code> function, I noted that if this documents <code>isManager</code> is set to true, I need to find a way to check that there isn't already a <code>person</code> document referenced by the same project that is also a manager.</p>
  
  <p>Knowing which project is referencing this document isn't an issue, I will have that somewhere, I just need to know how to run a query.. is that possible?</p>