title: Average nested list document fields in MongoDB
body: <p>I have a collection of documents that have a <code>field</code> of nested structure:</p>
  
  <pre><code>                        'field':[[x1,y1],...,[xN,yN]]
  </code></pre>
  
  <p>I am performing an aggregation by two fields and naively trying to return averaged "field" for each group:</p>
  
  <pre><code>    db.collection.aggregate([
                                 { $group: 
                                       {
                                           _id:{ a:"$field1", b:"$field2" },
                                           avgField:{$avg:"$field"}
                                       } 
                                 }
                              ])
  </code></pre>
  
  <p>Averaging, obviously, doesn't work as I want it to. So the question is:
  how can I return </p>
  
  <pre><code>                   avgField:[[&lt;x1&gt;,&lt;y1&gt;],...,[&lt;xN&gt;,&lt;yN&gt;]]
  </code></pre>
  
  <p>for each group, where &lt;> is averaging operator?</p>
  
  <hr>
  
  <p>Sample document: </p>
  
  <pre><code>{
  "_id" : ObjectId("551e77f803895f4329fec908"),
  "time_added" : {
      "date" : "2015-04-03",
      "weekday" : 4,
      "hour" : 4
  },
  "item" : {
  
  
          "field" : [
              [
                  [
                      1.1,
                      22.3
                  ],
                  [
                      1.5,
                      19.8
                  ]
              ]
  
            },
            "item_id" : "161712665"
  }
  }
  </code></pre>
  
  <p>So I want to average "field" for documents that dated by same weekday and hour as I described above</p>