title: How to sum all the values in an array in mongodb?
body: <p>I have this document</p>
  
  <pre><code>{
      "_id" : ObjectId("5e7948fc9a0d0e5ca78aa886"),
      "product_id" : ObjectId("5e76c896eebef71b39aa8277"),
      "user_qty" : [
          {
              "user_id" : ObjectId("5e76c997eebef71b39aa827a"),
              "qty" : 20
          },
          {
              "user_id" : ObjectId("5e794aa19a0d0e5ca78aa887"),
              "qty" : 40
          }
      ],
      "price" : 20,
      "reviews" : [
          {
              "name" : "Pablo Perez",
              "comment" : "Me quedan muy bien!"
          },
          {
              "name" : "Corina Smith",
              "comment" : "Muy nice"
          }
      ],
      "location" : {
          "street" : "La Bonita",
          "city" : "Caracas",
          "country" : "Venezuela"
      }
  }
  </code></pre>
  
  <p>I would like to make a query that returns the sum of all the quantities (qty) in the array <code>user_qty</code>. 
  In this document, it would be <code>20 + 40 = 60</code>. Any help?</p>