title: Querying 64-bit numbers in MongoDB with javascript
body: <p>I have a mongodb document with an array that contains both normal numbers (32-bit) and 
  big ones (64-bits), and I query this document with the node javascript driver for mongodb.  </p>
  
  <p>When querying the document in a mongo shell, I can see 64-bit numbers printed as NumberLong.  For example: <code>NumberLong("1099511627776")</code></p>
  
  <p>Basically I have two questions: </p>
  
  <p>(1) Is there a clean way to check if a value is a 64-bit number?  Today I use the following expression which is by elimination</p>
  
  <pre><code>if (typeof counters[slot] !== "number") {
      // I assume counters[slot] is a 64-bit object
  }
  </code></pre>
  
  <p>(2) How do I cast this value to an instance of <code>mongo.Long</code>?  Today I cast to mongo.Long in a convoluted way.  Is there a cleaner way to perform the cast?</p>
  
  <pre><code>var mongoLong = require('mongodb').Long;
  if (typeof counters[slot] !== "number") {
      var bigNumber = mongoLong(counters[slot].low_, counters[slot].high_);
      // do things with bigNumber
  }
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>Note: 
  One may wonder why I need to cast a Long to a Long.
  The reason is because the "Long" value which was
  returned by the MongoDB javascript driver query is <strong>not really an instance of the Long class</strong>.  i.e.
  it wasn't created with a Long() constructor, i.e. you cannot invoke the member functions on it, like getHighBits(), or isNegative().</p>