title: Mongodb $sum with Subarray list item values
body: <p><strong>I am trying to calculate total number of products in my order which was actually in sub-array.</strong></p>
  
  <p><strong>Facing trouble with $sum while trying to calculate.</strong> </p>
  
  <p>My Attempt</p>
  
  <pre><code>db.getCollection('orders').aggregate([
  {$match:{'order_no':'GHT19'}},
  {$unwind:"$products_list"}
  ])
  </code></pre>
  
  <p>My Result </p>
  
  <pre><code>{
      "_id" : ObjectId("57838a3a3628f76b52511ffe"),
      "order_no" : "GHT19",
      "origin_port" : "Vizag Port",
      "destination_port" : "Hankou Port"
      "products_list" : {
          "box_no" : "1",
          "product_name" : "Mobile",
          "qty" : "5"
      }
  }
  
  
  {
      "_id" : ObjectId("57838a3a3628f76b52511ffe"),
      "order_no" : "GHT19",
      "origin_port" : "Vizag Port",
      "destination_port" : "Hankou Port"
      "products_list" : {
          "box_no" : "2",
          "product_name" : "Television",
          "qty" : "2"
      }
  }
  
  
  {
      "_id" : ObjectId("57838a3a3628f76b52511ffe"),
      "order_no" : "GHT19",
      "origin_port" : "Vizag Port",
      "destination_port" : "Hankou Port",
      "products_list" : {
          "box_no" : "3",
          "product_name" : "Radio",
          "qty" : "2"
      }
  
  }
  </code></pre>
  
  <p>While trying to do SUM like below</p>
  
  <pre><code>db.getCollection('orders').aggregate([
  {$match:{'order_no':'GHT19'}},
  {$unwind:"$products_list"},
  {$group: {
      _id: '$products_list.box_no', 
      "total_products": {$sum: "$products_list.qty" }
    }
  }
  ])
  </code></pre>
  
  <p>I am getting ZERO result. Please see the below result.</p>
  
  <pre><code>{
      "_id" : "2",
      "total_products" : 0
  }
  
  
  {
      "_id" : "3",
      "total_products" : 0
  }
  
  
  {
      "_id" : "1",
      "total_products" : 0
  }
  </code></pre>
  
  <p>Please find the best solution for my issue.</p>