title: mongodb date insert like using mongoose
body: <p>I am inserting bulk records in mongodb. I am using the native DB drivers to do this, as the performance is much higher. At other points in my application, i am using mongoose. The problem I am having is that mongoose translates the date into a different format whereas mongodb native just inserts it as the number of seconds since 1970. So later queries in mongoose based off that date do not work.</p>
  
  <p>Here's my mongoose schema:</p>
  
  <pre><code>var MySchema = new Schema({
    name              : { type: String, required: true },
    updatedAt         : Date
  });
  </code></pre>
  
  <p>And my mongo db mass insert:</p>
  
  <pre><code>var newRec = { 
      name        : entry.Name, 
      updatedAt   : Date.now
  };
  newRecords.push(newRec);
  
  MySchema.collection.insert(newRecords, function(err, newRecs) {
              res.json(newRecs.ops);
            });
  </code></pre>
  
  <p>This produces in the DB:</p>
  
  <pre><code>{
      "_id": {
          "$oid": "562818ecf24d540f0053a38d"
      },
      "name": "Cool Record",
      "updatedAt": 12312423512
  }
  </code></pre>
  
  <p>Whereas if it was run through Mongoose it would produce:</p>
  
  <pre><code>{
      "_id": {
          "$oid": "561fd90285b5e73f5626f74e"
      },
      "name": "Cool Record",
      "updatedAt": {
          "$date": "2015-10-20T20:01:17.553Z"
      }
  }
  </code></pre>
  
  <p>If going through mongoose, queries like this work well:</p>
  
  <pre><code>MySchemda.find({ updatedAt : { $gt: lastSynced }}).exec();
  </code></pre>
  
  <p>But do not work otherwise.</p>