title: Mongodb: Is it possible to run map-reduce command and query strings as integers
body: <p>So I have the following PHP code which runs a map-reduce command on a MongoDB database collection:</p>
  
  <pre><code>$map = new MongoCode("function() { emit(this.app, this.bytes); }");
  $reduce = new MongoCode("function(k, vals) { ".
      "var sum = 0;".
      "for (var i in vals) {".
          "sum += vals[i];".
      "}".
      "return sum; }");
  
  $dateAdded = mktime(0,0,0,5,1,2015);
  //echo $dateAdded." = ".date("r",$dateAdded)."&lt;br&gt;\n";
  
  $request = $db-&gt;command(array(
      "mapreduce" =&gt; "log",
      "map" =&gt; $map,
      "reduce" =&gt; $reduce,
      "query" =&gt; array("event" =&gt; "destroy", "systimelong" =&gt; array('$gt' =&gt; $dateAdded)),
      "out" =&gt; array("inline" =&gt; 1)));
  
      var_dump($request);
  </code></pre>
  
  <p>This actually works really great when the data is stored in the database as an integer.  But sometimes the data gets stored as a string.  Why?  Thats another story that cant be changed right now.  Ultimately it will be an integer, but I'd really like to know if and how I can modify this to handle the cases that the data is a string just in case it ever happens.</p>
  
  <p>Since Mongo uses Javscript I feel like I should be able to use the <code>parseInt()</code> function inside the <code>$map</code> and/or<code>$reduce</code> functions, but it doesn't seem to be working.  </p>
  
  <p>Also, how would I handle the query?  The systimelong field is just unixtime, and I am using the PHP <code>mktime()</code> function to generate a integer value for the beginning of the month.  Again, it works great then comparing integers, but I need to first convert the string value.  </p>
  
  <p>Any ideas?</p>