title: MongoDB Aggregation Framework $group using nested operations
body: <p>I have several numeric fields that I need to aggregate. Let's say my document is structured as follows:</p>
  
  <pre><code>_id: 1234,
  numValue1: 10,
  numValue2: 20,
  numValue3: 30,
  numValue4: 40
  </code></pre>
  
  <p>If I wanted to add a computed field to my pipeline using one of the numeric fields, I could do something like this:</p>
  
  <pre><code>db.myCollection.aggregate(
  { 
    $project : {
      someComputedField : { $add:["$numValue1", 15] }
    }
  })
  </code></pre>
  
  <p>If I wanted to add a computed field based on two of these fields, I know I could do something like this:</p>
  
  <pre><code>db.myCollection.aggregate(
  { 
    $project : {
      someComputedField : { $add:["$numValue1", "$numValue2"] }
    }
  })
  </code></pre>
  
  <p>Now, my question is what if I needed to do $numValue1 + $numValue2 + $numValue3 + $numValue4?</p>
  
  <p>Or even more interestingly $numValue1 * ($numValue2 + $numValue3) / $numValue4?</p>