title: How to insert document field value as ISODate with Ruby MongoDB driver?
body: <p>It may be really simple, but the obvious is elusive at the moment in Ruby land.</p>
  
  <p>How do I insert document field value as ISODate and NOT a string with Ruby MongoDB driver? When I query a collection inside the MongoDB shell, I want the timestamp to be an ISODate object:</p>
  
  <pre><code>{
    "_id": ObjectId("570348904b3833000addcd67"),
    "timestamp": ISODate("2016-04-04T21:23:52.058Z")
  }
  </code></pre>
  
  <p>And <strong>NOT</strong>:</p>
  
  <pre><code>{
    "_id": ObjectId("570348904b3833000addcd67"),
    "timestamp": "2016-04-04T21:23:52.058Z" // or ms since epoch
  }
  </code></pre>
  
  <p>Please don't suggest I use ms|s since epoch. It's not a solution here.</p>
  
  <p>I've tried...</p>
  
  <pre><code>logs = []
  t = Time.at(1448064510963.fdiv(1000))
  mongo_hash['timestamp'] = t # --&gt; String
  mongo_hash[:timestamp] = t # --&gt; String
  mongo_hash['timestamp'] = t.to_datetime # --&gt; Weird Date String
  mongo_hash['timestamp'] = t.to_date # --&gt; String without time
  logs &lt;&lt; mongo_hash
  </code></pre>
  
  <p>I'm pushing <code>mongo_hash</code> into an array that's passed into <code>insert_many</code>.</p>
  
  <pre><code>mongo_client[:logs].insert_many(logs)
  </code></pre>
  
  <p>...and what I get in MongoDB 3.0.x is a string for the timestamp using Ruby Mongo driver v2.2.4...</p>
  
  <pre><code>{
    "_id": ObjectId("573107ac4f5bd9ac14920bb0"),
    "timestamp": "2015-11-20T11:59:43.127-08:00"
  }
  </code></pre>
  
  <p>Piece of cake in JS/Python... why so weird, Ruby? Whyyyy?</p>