title: Missing property on MongoDB document after initialising and saving with Mongoose
body: <p>I've encountered a problem trying to initialise and then save several properties to a new MongoDB document using the Mongoose constructor. The problem is that one of the properties I'm trying to save does not persist to the database, despite being in my schema.</p>
  <p><strong>Schema:</strong></p>
  <pre><code>const userSchema = new Schema({
    mentorAllowedContentUrls: [String],
    mentorAllowedRegions: [{
      type: String,
      enum: ['anz', 'europe']
    }],
  })
  </code></pre>
  <p><strong>My executing code:</strong></p>
  <pre><code>const newUser = new User();
  
  newUser.mentorAllowedContentURLs = ['randomUrl'];
  newUser.mentorAllowedRegions = ['anz'];
  
  await newUser.save()
  </code></pre>
  <p>After running the above code, I would expect a new user to appear in the database with both the <code>mentorAllowedContentURLs</code> and <code>mentorAllowedRegions</code> arrays. However, the <code>mentorAllowedRegions</code> array is missing.</p>
  <p><strong>Logging</strong></p>
  <p>Adding some logs to help work out what's going on produces the following:</p>
  <pre><code>const newUser = new User();
  
  newUser.mentorAllowedContentURLs = ['randomUrl'];
  newUser.mentorAllowedRegions = ['anz']
  
  // property that doesn't exist on my schema - just to compare behaviour
  newUser.nonsense = 'hey!'
  
  console.log('1: ', newUser.mentorAllowedContentURLs);
  console.log('2: ', newUser.mentorAllowedRegions);
  console.log('3: ', newUser.nonsense);
  console.log('4: ', newUser);
  console.log('5: ', Object.keys(newUser));
  
  await newUser.save(function(err) {
    if(err) {
      console.log('ERROR: ', err)
    }
  })
  </code></pre>
  <p><em>Output in terminal:</em></p>
  <p><code>1: ['randomUrl']</code></p>
  <p><code>2: ['anz']</code></p>
  <p><code>3: hey!</code></p>
  <p><code>4: { mentorAllowedContentURLs: ['randomUrl'] }</code></p>
  <p><code>5: ['$__', 'isNew', 'errors', '_doc', 'mentorAllowedRegions', 'nonsense']</code></p>
  <p>The <code>ERROR</code> log does not appear</p>
  <p><strong>Thoughts/things I've tried</strong></p>
  <p>I've tried calling <code>markModified('mentorAllowedRegions')</code> before saving the document, to force Mongoose to recognise the updated path. I've also tried setting <code>mentorAllowedRegions</code> to be just an array of strings in the schema (exactly the same as for the <code>mentorAllowedContentURLs</code> property. Neither makes a difference.</p>
  <p>It seems as though the problem occurs prior to running <code>.save()</code>, as my property is already missing on the logged <code>newUser</code> object (log 4 above). However, the value can be accessed by referencing <code>newUser.mentorAllowedRegions</code> (log 2 above).</p>
  <p>This is the same behaviour as for my <code>nonsense</code>  property, so it seems as though Mongoose is treating <code>mentorAllowedRegions</code> in the same way as if it was not defined on the schema and is holding it at the top level of the object without adding it to the document's actual data (hence it appearing in the array at log 5).</p>
  <p>Running await <code>User.find({ mentorAllowedRegions: 'anz' })</code> executes with no problem and selects the right users from the db, so it appears Mongoose can use the property in other contexts.</p>
  <p>I wondered if anyone else has ever encountered a similar situation or can help shed any light as I'm running out of ideas to try!</p>