title: Mongoose mapReduce : reduce returns object or array?
body: <p>I Have the following Collection :</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>/* 0 */
  {
      "clientID" : ObjectId("51b9c10d91d1a3a52b0000b8"),
      "_id" : ObjectId("532b4f1cb3d2eacb1300002b"),
      "answers" : [],
      "questions" : []
  }
  
  /* 1 */
  {
      "clientID" : ObjectId("51b9c10d91d1a3a52b0000b8"),
      "_id" : ObjectId("532b6b9eb3d2eacb1300002c"),
      "answers" : [ 
          "1", 
          "8"
      ],
      "questions" : [ 
          "1", 
          "2", 
          "3"
      ]
  }
  
  /* 2 */
  {
      "clientID" : ObjectId("51b9c10d91d1a3a52b0000b8"),
      "_id" : ObjectId("532b6baeb3d2eacb1300002d"),
      "answers" : [ 
          "1", 
          "8"
      ],
      "questions" : [ 
          "1", 
          "2", 
          "3"
      ]
  }
  
  /* 3 */
  {
      "clientID" : ObjectId("5335f9d864e2b1290c00012e"),
      "_id" : ObjectId("533b828146ca43634000002d"),
      "answers" : [ 
          "ORANGE"
      ],
      "questions" : [ 
          "Color"
      ]
  }
  
  /* 4 */
  {
      "clientID" : ObjectId("5335f9d864e2b1290c00012e"),
      "_id" : ObjectId("5351be327b539a4d1a00002b"),
      "answers" : [ 
          "ORANGE"
      ],
      "questions" : [ 
          "Color"
      ]
  }
  
  /* 5 */
  {
      "clientID" : ObjectId("5335f9d864e2b1290c00012e"),
      "_id" : ObjectId("5351be5ec89d717d1a00002b"),
      "answers" : [ 
          "ORANGE"
      ],
      "questions" : [ 
          "Color"
      ]
  }
  </code></pre>
  
  <p>I am running the following code in order to find how many times the (questions,answers) combination appears in the collection:</p>
  
  <pre class="lang-js prettyprint-override"><code>o.map= function(){ 
      emit({"questions" : this.questions, "answers" :this.answers },this.clientID) 
  };
  
  o.reduce = function(answers, collection){
      return collection.length; 
  };
  
  logSearchDB.mapReduce(o,function (err, results) {
      results.sort(function(a, b){return b.value-a.value});
      for (var i = 0; i &lt; results.length; i++) {
          console.log(JSON.stringify(results[i]))
      };
  
  })
  </code></pre>
  
  <p>The output is:</p>
  
  <pre class="lang-js prettyprint-override"><code>{"_id":{"questions":[],"answers":[]},"value":"51b9c10d91d1a3a52b0000b8"}
  {"_id":{"questions":["Color"],"answers":["ORANGE"]},"value":3}
  {"_id":{"questions":["1","2","3"],"answers":["1","8"]},"value":2}
  </code></pre>
  
  <p>I expected that the first row will have "value" : 1</p>
  
  <p>I guess the 'reduce' function got a 'collection' object : "51b9c10d91d1a3a52b0000b8", instead of getting an  array : ["51b9c10d91d1a3a52b0000b8"].</p>
  
  <p>Why the map reduce doesn't collect everything into an array?</p>