title: Mongoose: Set default value in a required field when this is not present in the document to save
body: <p>I tried to set a default value in an empty field for a document to be saved in the MongoDB</p>
  
  <p>In my case, this is the mongoose schema</p>
  
  <pre><code>var Distribution = new Schema({
      temporalCoverage: {
          startDate: {type: Date, default: Date.now},
          endDate: {type: Date, default: Date.now}
      },
      distributionText: String
  });
  </code></pre>
  
  <p>This is the document to save:</p>
  
  <pre><code>"distribution": {
      "temporalCoverage": {
        "endDate": "",
        "startDate": ""
      },
      "distributionText": "test"
    }
  </code></pre>
  
  <p>In this document, the empty fields are endDate and startDate. The document is saved in mongoDB with null values.</p>
  
  <pre><code>"distribution": {
      "temporalCoverage": {
        "endDate": null,
        "startDate": null
      },
      "distributionText": "test"
    }
  </code></pre>
  
  <p>I want to save the default value, not null </p>
  
  <p>If a put the field required in the schema, <code>temporalCoverage : { startDate : { type: Date, required: true, default: Date.now }, endDate : { type: Date, required: true, default: Date.now } }</code>I get the error validation, and the document is no saved it. </p>