title: Mongodb: nested field in $group's _id
body: <p>Assume we have documents like this in the collection</p>
  
  <pre><code>{
      _id: {
          element_id: '12345',
          name: 'foobar'
      },
      value: {
          count: 1
      }
  }
  </code></pre>
  
  <p>I am using the aggregation framework to do a <code>$group</code>, like so</p>
  
  <pre><code>db.collection.aggregate([
      { $group: { _id: '$_id.element_id', total: { $sum: '$value.count' } } }
  ])
  </code></pre>
  
  <p>And got a result of </p>
  
  <pre><code>{ "result" : [ { "_id" : null, "total" : 1 } ], "ok" : 1 }
  </code></pre>
  
  <p><em>Notice that the <code>_id</code> field in the result is null.</em> From experimentation it seems that $group is not allowing a nested field declaration for its <code>_id</code> (e.g. <code>$_id.element_id</code>).</p>
  
  <p>Why is this? And is there a workaround for it?</p>
  
  <p>Thank you.</p>