title: Nested output from mongo aggregate query
body: <p>This is right out of the mongo aggregation documentation. Lets say I have these set of documents:</p>
  
  <pre><code>{ _id: 1, cust_id: "abc1", ord_date: ISODate("2012-11-02T17:04:11.102Z"), status: "A", amount: 50 }
  { _id: 2, cust_id: "xyz1", ord_date: ISODate("2013-10-01T17:04:11.102Z"), status: "A", amount: 100 }
  { _id: 3, cust_id: "xyz1", ord_date: ISODate("2013-10-12T17:04:11.102Z"), status: "D", amount: 25 }
  { _id: 4, cust_id: "xyz1", ord_date: ISODate("2013-10-11T17:04:11.102Z"), status: "D", amount: 125 }
  { _id: 5, cust_id: "abc1", ord_date: ISODate("2013-11-12T17:04:11.102Z"), status: "A", amount: 25 }
  </code></pre>
  
  <p>I can run this aggregate query:</p>
  
  <pre><code>db.orders.aggregate([
                   { $match: { status: "A" } },
                   { $group: { _id: "$cust_id", total: { $sum: "$amount" } } },
                   { $sort: { total: -1 } }
                 ])
  </code></pre>
  
  <p>To get this response:</p>
  
  <pre><code>{ "_id" : "xyz1", "total" : 100 }
  { "_id" : "abc1", "total" : 75 }
  </code></pre>
  
  <p>But what if a want the response in a nested format? Any way of achieving that without using mapReduce? Something like this:</p>
  
  <pre><code>{ "_id" : "xyz1", "amount": { "total" : 100 } }
  { "_id" : "abc1", "amount": { "total" : 75 } }
  </code></pre>