title: The map/reduce finalize() does not always get the same number of parameters
body: <p>When using map/reduce on MongoDb 2.0.1, it seems that the finalize method is not always called with the same arguments.</p>
  
  <p>I am doing a regular counting + average at the end.</p>
  
  <pre><code>var m = function() {
      emit(this.testName, {
          worked: Number(this.testStatus == "WORKED"),
          failed: Number(this.testStatus == "FAILED"),
          done: Number(this.testStatus == "DONE"),
          count: 1
      });
  }
  
  var r = function(key, values) {
      var result = {
          worked: 0,
          failed: 0,
          done: 0,
          count: 0
      }
  
      values.forEach(function(value) {
        result.worked += value.worked;
        result.failed += value.failed;
        result.done += value.done;
        result.count += value.count;
      });
  
      return result;
  }
  
  var f = function(key, value) {
      data = value || key;
      data.workedMean = data.worked / data.count;
      return data;
  }
  
  var cmd = {
      mapreduce: "tests",
      map: m,
      reduce: r,
      finalize: f,
      out: {
          reduce: "fromMongo"
      },
      jsMode: true
  }
  </code></pre>
  
  <p>When the <code>fromMongo</code> collection is empty, f() is called with only one argument, the <code>value</code>. When <code>fromMongo</code> already has values (notice that I use <code>reduce</code> as my <code>out</code> map/reduce parameter), the f() method get two arguments: <code>key</code> and <code>value</code>.</p>
  
  <p>Is that a known behavior?
  I managed two make it work using <code>data = value || key;</code>, but I don't think this is the solution. </p>