title: MongoDB - Count value occurrences for field
body: <p><strong>Document structure</strong></p>
  <pre><code>{
  &quot;A&quot;: &quot;1&quot;,
  &quot;B&quot;: &quot;3&quot;,
  &quot;C&quot;: &quot;0.000090213&quot;,
  },
  {
  &quot;A&quot;: &quot;1&quot;,
  &quot;B&quot;: &quot;3&quot;,
  &quot;C&quot;: &quot;0.000037698&quot;,
  },
  {
  &quot;A&quot;: &quot;2&quot;,
  &quot;B&quot;: &quot;4&quot;,
  &quot;C&quot;: &quot;0.00016664&quot;,
  }
  </code></pre>
  <p>I'm trying to get the count of value for specific fields with aggregation, desired result for A and B would be</p>
  <pre><code>A: { &quot;1&quot;: 2, &quot;2&quot;: 1}
  B: { &quot;3&quot;: 2, &quot;4&quot;: 1}
  </code></pre>
  <p>Any help is greatly appreciated.</p>