'mongoose simply strip out non valid attributes?

If I have a schema in mongoose that looks like (https://mongoosejs.com/docs/subdocs.html):

const childSchema = new Schema({ 
  name: 'string',
  age: 'number'
});

const parentSchema = new Schema({
  documentName: 'string'
  child: childSchema
});

const Parent = mongoose.model('Parent', parentSchema);

If i try to create a new doc with an alien in the child, eg:

const parent = new Parent({
   documentName: 'buildings',
   child: {
     name: 'Some Palace',
     age: '245',
     size: '17a'
   }
})

Is it possible to configure mongoose to persist the doc but simply strip out child.size from the input?

So in other words, the doc above would look like:

{
   documentName: 'buildings',
   child: {
     name: 'Some Palace',
     age: '245'
   }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source