title: mongodb mapreduce - build an array or object in the reduce?
body: <p>original collection: </p>
  
  <pre><code>{ 
  "_id" : ObjectId('xxxxxxxxxxxxxxxx'),
    "userId" : ObjectId('yyyyyyyyyyyyyyyy'),
    "urlId" : ObjectId('zzzzzzzzzzzzzzzzzz')
  },
  { 
    "_id" : ObjectId('uuuuuuuuuuuuuuuuuu'),
    "userId" : ObjectId('aaaaaaaaaaaaaaaa'),
    "urlId" : ObjectId('zzzzzzzzzzzzzzzzzz')
  }
  </code></pre>
  
  <p>emit:</p>
  
  <pre><code>emit(this.urlId, {userId: this.userId, visitCount: this.visitCount});
  </code></pre>
  
  <p>reduce:</p>
  
  <pre><code>function(key, values) {
      var visitCount = 0;
      var userVC = new Array();
      values.forEach(function(doc) {
  
  
  NOT SURE WHAT TO PUT HERE TO ACHIEVE DESIRED OUTPUT COLLECTION
  
  
      });
      return {urlId: key, userVC: userVC};
  };
  </code></pre>
  
  <p>desired MR output collection:</p>
  
  <pre><code>{
     "_id" : ObjectId('zzzzzzzzzzzzzzzzzzzz'),
     "value" : {
         "urlId" : ObjectId('zzzzzzzzzzzzzzzzzzzz'),
         "userVC" : {
                ObjectId('yyyyyyyyyyyyyyyy') : &lt;total visit count for this userId on this urlId&gt;,
                ObjectId('aaaaaaaaaaaaaaaa') : &lt;total visit count for this userId on this urlId&gt;
         }
  }
  </code></pre>