title: Sum in nested document MongoDB
body: <p>I'm trying to sum some values in an array of documents, with no luck.</p>
  
  <p>This is the Document</p>
  
  <p>db.Cuentas.find().pretty()</p>
  
  <pre><code>{
      "Agno": "2013",
      "Egresos": [
          {
              "Fecha": "28-01-2013",
              "Monto": 150000,
              "Detalle": "Pago Nokia Lumia a @josellop"
          },
          {
              "Fecha": "29-01-2013",
              "Monto": 4000,
              "Detalle": "Cine, Pelicula fome"
          }
      ],
      "Ingresos": [],
      "Mes": "Enero",
      "Monto": 450000,
      "Usuario": "MarioCares"
      "_id": ObjectId(....)
  }
  </code></pre>
  
  <p>So, i need the sum of all the "Monto" in "Egresos" for the <strong>"Usuario": "MarioCares"</strong>. In this example <strong>154000</strong></p>
  
  <p>Using aggregation i use this:</p>
  
  <pre><code>db.Cuentas.aggregate(
      [
          { $match: {"Usuario": "MarioCares"} },
          { $group: 
              {
                  _id: null,
                  "suma": { $sum: "$Egresos.Monto" }
              }
          }
      ]
  )
  </code></pre>
  
  <p>But i always get</p>
  
  <pre><code>{ "result" : [{ "_id" : null, "suma" : 0 }], "ok" : 1 }
  </code></pre>
  
  <p>What am i doing wrong ?</p>
  
  <p><strong>P.D.</strong> already see <a href="https://stackoverflow.com/questions/12162681/mongodb-2-1-aggregate-framework-sum-of-array-elements-matching-a-name">this</a> and <a href="https://stackoverflow.com/questions/8874671/taking-sum-of-column-in-mongodb">this</a></p>