Mongoose Mixed type field with dates
<p>I'm creating an app where a user can create various types of custom fields, and I'd like to store those fields in mongo.  The types will include String, Number, and Date.  My schema looks like this:</p>

<pre><code>const MetaSchema = new mongoose.Schema({
  key: String,
  value: {type: mongoose.Schema.Types.Mixed},
  type: String,
  created_at: {type: Date, default: Date.now}
});
</code></pre>

<p>This works great, and I can store my data as expected.  The issue is, when I want to store a date for instance, that gets sent across to the server in ISO format, a payload that might look like:</p>

<pre><code>{
  "key": "Contract Signed",
  "value": "2016-04-06T22:35:11.540Z",
  "type": "date"
}
</code></pre>

<p>Any way I can get mongo / mongoose to treat and store this like a date instead of a string?  If I set this to type date then I think it would do the trick, but I have to save just about anything they can come up with for custom fields.  Thanks so much!</p>

<p>TLDR: Can a mixed data type in mongoose / mongo be treated differently based on the type of data being inserted (IE Date vs String).</p>