title: How to group mongodb aggregate array of objects data To sum numbers on the same date
body: <p>I'm trying to create charts but I can't combine the data to be like &quot;Expected result below&quot;</p>
  <p>What can I use to return &quot;Expected result&quot;.</p>
  <p>I tried using $group in $group and $reduce and it didn't work well.</p>
  <p>I hope someone can help me solve this task</p>
  <p><strong>Current result is</strong></p>
  <pre><code>[
     {
        &quot;_id&quot;:&quot;5fd4c3586e83b334d97c5218&quot;,
        &quot;consumption&quot;:5,
        &quot;charts&quot;:[
           {
              &quot;date&quot;:&quot;2020-10&quot;,
              &quot;consumption&quot;:1
           },
           {
              &quot;date&quot;:&quot;2020-10&quot;,
              &quot;consumption&quot;:1
           },
           {
              &quot;date&quot;:&quot;2020-11&quot;,
              &quot;consumption&quot;:1
           },
           {
              &quot;date&quot;:&quot;2020-11&quot;,
              &quot;consumption&quot;:1
           }
        ]
     }
  ]
  
  </code></pre>
  <p><strong>Expected result is</strong></p>
  <pre><code>[
     {
        &quot;_id&quot;:&quot;5fd4c3586e83b334d97c5218&quot;,
        &quot;consumption&quot;:5,
        &quot;charts&quot;:[
           {
              &quot;date&quot;:&quot;2020-10&quot;,
              &quot;consumption&quot;:2
           },
           {
              &quot;date&quot;:&quot;2020-11&quot;,
              &quot;consumption&quot;:2
           },
     }
  ]
  </code></pre>