title: Mongo aggregate nested array
body: <p>I have a mongo collection with following structure</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>{
      "userId" : ObjectId("XXX"),
      "itemId" : ObjectId("YYY"),
      "resourceId" : 1,
      "_id" : ObjectId("528455229486ca3606004ec9"),
      "parameter" : [
          {
              "name" : "name1",
              "value" : 150,
              "_id" : ObjectId("528455359486ca3606004eed")
          },
          {
              "name" : "name2",
              "value" : 0,
              "_id" : ObjectId("528455359486ca3606004eec")
          },
          {
              "name" : "name3",
              "value" : 2,
              "_id" : ObjectId("528455359486ca3606004eeb")
          }
      ]
  }
  </code></pre>
  
  <p>There can be multiple documents with the same 'useId' with different 'itemId' but the parameter will have same key/value pairs in all of them.</p>
  
  <p>What I am trying to accomplish is return aggregated parameters "name1", "name2" and "name3" for each unique "userId" disregard the 'itemId'. so final results would look like for each user :</p>
  
  <pre class="lang-js prettyprint-override"><code>{
    "userId" : ObjectId("use1ID"),
    "name1" : (aggregatedValue),
    "name2" : (aggregatedValue),
    "name3" : (aggregatedVAlue) 
  },
  {
    "userId" : ObjectId("use2ID"),
    "name1" : (aggregatedValue),
    "name2" : (aggregatedValue),
    "name3" : (aggregatedVAlue) 
  }
  </code></pre>
  
  <p>Is it possible to accomplish this using the aggregated methods of mongoDB ? Could you please help me to build the proper query to accomplish that ? </p>