I apologize if the title is not precise enough, I'm not sure how to describe my problem better. I have the following data:
Category: A, Group: 1
Category: A, Group: 1
Category: A, Group: 2
Category: A, Group: 3
Category: B, Group: 5
Category: B, Group: 5
I would need to group by Category and Group count, so that the result would look like:
Category A: 3
Category B: 1
I was able to only group by category so far
{ $group: { _id: "$category", count:{$sum:1} } }
However, I'm not sure how to count the distinct groups?