title: How to count Each rating using mongoose aggregate function
body: <p>How do I calculate rating count based on each rating using mongoose aggregate function? I have the collection below:</p>
  
  <pre><code>[
  
  {
      "ProjectName":"AAA",
      "Emp":[
          {
              "Emp":{
                  "EmpID":"1",
                  "Rating":2.5
              }
          },
          {
              "Emp":{
                  "EmpID":"2",
                  "Rating":2
              }
          },
          {
              "Emp":{
                  "EmpID":"2",
                  "Rating":2.5
              }
          }
      ]
  },
  {
      "ProjectName":"BBB",
      "Emp":[
          {
              "Emp":{
                  "EmpID":"1",
                  "Rating":3
              }
          },
          {
              "Emp":{
                  "EmpID":"1",
                  "Rating":4
              }
          },
          {
              "Emp":{
                  "EmpID":"2",
                  "Rating":4
              }
          }
      ]
  },
  {
      ..
  }
  </code></pre>
  
  <p>]</p>
  
  <p>I am expecting the response below:  </p>
  
  <pre><code>[{
  
      "projectName":"AAA",
      "Rating":[
          {
              "Rate":0.5,
              "Count":0
          },
          {
              "Rate":1,
              "Count":0,
              "Percentage":0
          },
          {
              "Rate":1.5,
              "Count":0
          },
          {
              "Rate":2,
              "Count":0
          },
          {
              "Rate":2.5,
              "Count":0
          },
          {
              "Rate":3,
              "Count":1
          },
          {
              "Rate":3.5,
              "Count":0
          },
          {
              "Rate":4,
              "Count":2
          },
          {
              "Rate":4.5,
              "Count":0
          },
          {
              "Rate":5,
              "Count":0
          }
      ]
  },
  {
      "projectName":"BBB",
      "Rating":[
          {
              "Rate":0.5,
              "Count":0
          },
          {
              "Rate":1,
              "Count":0,
              "Percentage":0
          },
          {
              "Rate":1.5,
              "Count":0
          },
          {
              "Rate":2,
              "Count":1
          },
          {
              "Rate":2.5,
              "Count":2
          },
          {
              "Rate":3,
              "Count":0
          },
          {
              "Rate":3.5,
              "Count":0
          },
          {
              "Rate":4,
              "Count":0
          },
          {
              "Rate":4.5,
              "Count":0
          },
          {
              "Rate":5,
              "Count":0
          }
      ]
  
  },{...}]
  </code></pre>
  
  <p>Ho do I solve this problem?</p>