title: How to aggregate data to nested array output
body: <p>So I have the following data in a collection</p>
  
  <blockquote>
    <p>{ "UID" : 567, "AN0" : 100, "AN1" : 150, epoch:1401399336437 } <br>
    { "UID" : 123, "AN0" : 200, "AN1" : 250, epoch:1401399336438 } <br>
    { "UID" : 567, "AN0" : 300, "AN1" : 350, epoch:1401399336439 } <br>
    ...</p>
  </blockquote>
  
  <p>For UID:567 &amp;&amp; AN0 I want to get an output similar to:</p>
  
  <blockquote>
    <p>{ key : "AN0",<br>
      values: [<br>
    &nbsp;&nbsp;[1401399336437,  100 ]<br>
    &nbsp;&nbsp;[1401399336439,  300 ]<br>
      ]<br>
    }<br></p>
  </blockquote>
  
  <p>I already more or less did it using GROUP like the following:</p>
  
  <pre><code>db.Datasets.group({ 
        cond: {UID: "567", AN0:{$exists:true}, epoch:{$exists:true}},
        initial: {key:"", values: []}, 
        reduce: function(obj, prev){ 
          var temp =[];
          temp.push(obj.epoch);
          temp.push(obj.AN0);
          prev.values.push(temp);
        },
        finalize: function(result){
            result.key = "AN0";
        }
  })
  </code></pre>
  
  <p>However this method gave me alot of issues when sharing the scope with the reduce and finalize functions.</p>
  
  <p><b>So I would like to do the same with the aggregation pipeline</b></p>
  
  <p>I tried</p>
  
  <pre><code>db.Datasets.aggregate( [ 
      {$match:{ UID: "567" , AN0: {$exists:true} }}, 
      {$group : { _id: "$UID", value1:  { $push:  "$epoch"}, value2:  { $push:  "$AN0"} }},
  ] )
  </code></pre>
  
  <p>I get </p>
  
  <blockquote>
    <p>{ value1:[ 1401399336437, 1401399336439 ],<br>
    &nbsp;&nbsp;value2:[ 100, 300 ]</p>
  </blockquote>
  
  <p>How do change that to get</p>
  
  <blockquote>
    <p>value: [<br>
    &nbsp;&nbsp;[1401399336437,  100 ]<br>
    &nbsp;&nbsp;[1401399336439,  300 ]<br>
      ]<br></p>
  </blockquote>
  
  <p>Thanks!</p>