MongoDB Aggregation: Counting distinct fields

前端 未结 8 2233
礼貌的吻别
礼貌的吻别 2020-12-13 04:33

I am trying to write an aggregation to identify accounts that use multiple payment sources. Typical data would be.

{
 account:\"abc\",
 vendor:\"amazon\",
}         


        
8条回答
  •  -上瘾入骨i
    2020-12-13 05:10

    I do not see why somebody would have to use $group twice

    db.t2.aggregate([ { $group: {"_id":"$account" , "number":{$sum:1}} } ])
    

    This will work perfectly fine.

提交回复
热议问题