MongoDB equivalent of SQL COUNT GROUP BY

后端 未结 1 2013
栀梦
栀梦 2021-01-28 19:21

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

相关标签:
1条回答
  • 2021-01-28 19:43

    You first $group on _id:"$a" with $sum:{1} (this is basically your count on distinct a) then sort on the sum.

    0 讨论(0)
提交回复
热议问题