title: How to calculate sum of fields from mongodb collection documents using mongoose
body: <p>I want to perform sum of employee points from mongodb documents.</p>
  
  <p>My Documents in Employee Points Collections are like below</p>
  
  <pre><code>[
      {
          "EmployeeID": "Cust0001",
          "Point": 1,
      },
      {
          "EmployeeID": "Cust0002",
          "Point": 2,
      },
      {
          "EmployeeID": "Cust0003",
          "Point": 1,
      },
      {
          "EmployeeID": "Cust0001",
          "Point": 5,
      },
      {
          "EmployeeID": "Cust0001",
          "Point": 2,
      }
  ]
  </code></pre>
  
  <p>Expected result</p>
  
  <pre><code>[
      {
          "EmployeeID": "Cust0001",
          "Total_Points": 8
      },
      {
          "EmployeeID": "Cust0002",
          "Total_Points": 2
      },
      {
          "EmployeeID": "Cust0003",
          "Total_Points": 1
      }
  ]
  </code></pre>
  
  <p>Which is the best and most optimized way to get the output from mongodb with the total points.</p>
  
  <p>I am using mongoose mongodb connection in my project.</p>
  
  <p>I can manipulate data using a for loop but it seems rather inefficent.</p>
  
  <p>Thanks in advance.</p>
  
  <p>Comments are appreciated.</p>