Been reading the mongodb aggregation and group docs, however still unclear to me.
Consider the collection with docs:
{ a : 1, b : 0 }
{ a : 1, b
You first $group on _id:"$a" with $sum:{1} (this is basically your count on distinct a) then sort on the sum.
$group
_id:"$a"
$sum:{1}
sort