title: How to format data in Model before saving in Mongoose (ExpressJS)
body: <p>I get Date from user in the string format and I currently convert into a Date in controller before creating the Schema object and saving. Is there a way to move this logic to model as it seems to me that Model is the right place for this</p>
  
  <pre><code>var RunSchema = new Schema({
      created: {
          type: Date,
          default: Date.now
      },
      starttime: {
          type: Date,
          default: Date.now
      }
  
  });
  </code></pre>
  
  <p>Currently I do this</p>
  
  <pre><code>//req.body = {starttime;'2.05.2013 11:23:22'}
  var run = new Run(req.body);
  // util.getDate(datetime) returns false if invalid and Date() if valid
  // req.body.starttime = '2.05.2013 11:23:22';
  run.starttime = util.getDate(req.body.starttime);
  run.save(function(err) {
      if(err) {
      } else {
      }
  });
  </code></pre>
  
  <p>On a sidenote, how do I assert if I want to process the param in custom function checks. Something like</p>
  
  <pre><code>    req.assert('name', 'Name can\'t be empty').len(1, 1000);
  </code></pre>