title: Mongodb Aggregation to get count of records with groupby
body: <p>I have Signal record collection below:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>Signal records:
  
  [
    {
      "id": "5dc250e0d972e71c3b3e6e88",
      "signalStrength": -180,
      "signalbars": "3",
      "employee": "5db59227f0204855654075ee",
      "store": "5dc25092d972e71c3b3e6e87",
      "carrierName": "LT&amp;T"
    },
    {
      "id": "5dc251f723760a24de167f8e",
      "signalStrength": -180,
      "signalbars": "3",
      "employee": "5db59227f0204855654075ee",
      "store": "5dc25092d972e71c3b3e6e87",
      "carrierName": "Sprint"
    },
    {
      "id": "5dc289affd1ea02f0fceb9ac",
      "signalStrength": -80,
      "signalbars": "3",
      "employee": "5db59227f0204855654075ee",
      "store": "5dc2899bfd1ea02f0fceb9ab",
      "carrierName": "LT&amp;T"
    }
  ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>Basically i need to calculate carrier name based average values and total number of employees who has signal records for that carrier name</p>
  
  <p>And i need to get following results</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>[
        {
          "_id": "LT&amp;T",
          "averageSignal": -130,
          "strongestSignal": -80,
          "weakestSignal": -180,
          "averageBars": 3,
          "totalTests": 2,
          "totalTesters": 1
        },
        {
          "_id": "Sprint",
          "averageSignal": -180,
          "strongestSignal": -180,
          "weakestSignal": -180,
          "averageBars": 3,
          "totalTests": 1,
          "totalTesters": 1
        }
  ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>My code looks below for aggregation:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>[
    {
      $match: query
    },
    {
      $group:
      {
        _id: "$carrierName",
        averageSignal: { $avg: "$signalStrength" },
        strongestSignal: { $max: "$signalStrength" },
        weakestSignal: { $min: "$signalStrength" },
        averageBars: { $avg: "$signalbars" },
        totalTests: { $sum: 1 },
      }
    },
    { $sort: { carrierName: -1 } },
  ]</code></pre>
  </div>
  </div>
  </p>
  
  <p>am stuck how find total testers on above query</p>
  
  <p>Any help would be great</p>