title: MongoDB aggregate objects with an array of objects?
body: <p>Here is a part of my collection in <code>json</code>:</p>
  
  <pre><code>[{"company":"Lenovo", "models": 
      [{"model":"ThinkPad T400", "gens": 
          [{"gen":"3", "start":2012},
          {"gen":"2", "start":2008},
          {"gen":"1", "start":2004}]
      }...]
  }...]
  </code></pre>
  
  <p>I am trying to come-up with an aggregate command that will return me the following:</p>
  
  <pre><code>[{ "_id":"Lenovo", 
    "models":[{ "model": "ThinkPad T400", 
                "gens":["1","2","3"]
              }...]
  }...]
  </code></pre>
  
  <p>I have tried the following aggregate command but it didn't work:</p>
  
  <pre><code>db.makes.aggregate([{
      $group:{
          _id: '$company',
          models: { $push:  { 
              model: "$models.model", 
              gen: "$models.gens.gen"
          }} 
      } 
  }])
  </code></pre>
  
  <p>I get this result:</p>
  
  <pre><code>[{ "_id":"Lenovo", 
    "models":[{ "model": ["ThinkPad T400"], 
                "gens":[ ["1","2","3"] ]
              }...]
  }...]
  </code></pre>
  
  <p>It is probably because each my object has an array of objects (Models) and that objects have an array of objects too (Gens).</p>
  
  <p><strong>What is the right request to the MongoDB that would return me my expected result?</strong></p>