title: mongodb aggregation and sorting on nested array
body: <p>Below is my mongo db document structure</p>
  
  <pre><code>{
  "product_json": {
  "productId": 1,
  "productData": [
    {
      "productName": "A",
      "productDetails": [
        {
          "manufacturedDate": "2014-08-09",
          "name": "A1",
          "size": 300
        },
        {
          "manufacturedDate": "2012-08-09",
          "name": "A2",
          "size": 200
        }
      ]
    },
    {
      "productName": "B",
      "productDetails": [
        {
          "manufacturedDate": "2015-08-09",
          "name": "B1",
          "size": 300
        },
        {
          "manufacturedDate": "2017-08-09",
          "name": "B2",
          "size": 200
         }
       ]
     }
   ]
  }
  }
  </code></pre>
  
  <p>I need to group by on "manufacturedDate" and apply sorting.Also i dont want the whole document as match.only the matched object(matched productDetails object).</p>