title: Group records and get sum of the groups separately
body: <p>I have a Loading sheet model in my mongo database. The loading sheet has an attribute called &quot;records&quot; which is a type of Array of objects (shown below).</p>
  <p><a href="https://i.stack.imgur.com/UktZb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UktZb.png" alt="enter image description here" /></a></p>
  <p>I need to save the sum of sales amount after grouping the &quot;records&quot; by &quot;type&quot;. something like below</p>
  <pre><code>5f6c057e1243640024832ef2 : 94.8
  5f6c058f1243640024832ef3 : 355.9 + 3000
  5f6c058f1243640024832ef4 : 2690.43 
  </code></pre>
  <p>I need above 3 types of sums for another calculation in the future.</p>
  <p>What could be the best approach of doing this? Is it to calculate the amounts for those types separately from the front end and send the values to back end or is there any other way to get it done (I know that we can show the data using aggregate pipelines in mongodb).</p>
  <p>My main concern is how to get the values saved to the database so that I can use those amounts for those types in other calculations in the future</p>
  <p>Any advice is much appreciated.</p>