title: Type Checking in Mongoose Maps
body: <p>If I have the following schema:</p>
  
  <pre><code>const userSchema = new mongoose.Schema({
    modules: {
      type: Map,
      of: {
        name: {
          type: String,
          required: true
        }
      }
    }
  })
  </code></pre>
  
  <p>Theoretically, mongoose should validate the type of each <code>UserModule</code> when I create a new document, ensuring the required <code>name</code> property is present.</p>
  
  <p>However, if I create a user with a module without the <code>name</code> property:</p>
  
  <pre><code>await User.create({ modules: { example: {} } })
  </code></pre>
  
  <p>No error is thrown. Normally, mongoose is able to correctly validate for required types.</p>
  
  <p>Workarounds I can think of include either hardcoding the keys for each module (and not use a map) or including a validator on the <code>modules</code> map to check all modules have the required keys are present, none of which are ideal.</p>
  
  <p>Is there a better way to check the type of map values?</p>