title: Combining group and project in mongoDB aggregation framework
body: <p>my document looks like this:</p>
  
  <pre><code>{ 
    "_id" : ObjectId("5748d1e2498ea908d588b65e"), 
    "some_item" : {
      "_id" : ObjectId("5693afb1b49eb7d5ed97de14"), 
      "item_property_1" : 1.0, 
      "item_property_2" : 2.0,
    }, 
    "timestamp" : "2016-05-28",  
    "price_information" : {
      "arbitrary_value" : 111, 
      "hourly_rates" : [
          {
              "price" : 74.45, 
              "hour" : "0"
          }, 
          {
              "price" : 74.45, 
              "hour" : "1"
          }, 
          {
              "price" : 74.45, 
              "hour" : "2"
          }, 
      ]
    }
  }
  </code></pre>
  
  <p>I did average the price per day via:</p>
  
  <pre><code>db.hourly.aggregate([
    {$match: {timestamp : "2016-05-28"}},
    {$unwind: "$price_information.hourly_rates"},
    {$group: { _id: "$unique_item_identifier", total_price: { $avg: "$price_information.hourly_rates.price"}}}
  ]);
  </code></pre>
  
  <p>I am struggling with bringing (projecting) other params with in the result set. I would like to have also <code>some_item</code> and <code>timestamp</code>in the result set. I tried to use a <code>$project: {some_item: 1, total_price: 1, ...}</code> within the query, but that wasn't right. </p>
  
  <p>My desired output would be like:</p>
  
  <pre><code>{ 
    "_id" : ObjectId("5693afb1b49eb7d5ed97de27"), 
    "someItem" : {
      "_id" : ObjectId("5693afb1b49eb7d5ed97de14"), 
      "item_property_1" : 1.0, 
      "item_property_2" : 2.0,
    }, 
    "timestamp" : "2016-05-28",  
    "price_information" : {
      "avg_price": 34
    }
  }
  </code></pre>
  
  <p>If somebody could give me a hint, how to project the grouping and the other params into the result set, I would be thankful.</p>
  
  <p>Best
  Rob</p>