MongoDB Aggregation: Counting distinct fields

前端 未结 8 2279
礼貌的吻别
礼貌的吻别 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条回答
  •  半阙折子戏
    2020-12-13 05:12

    db.UserModule.aggregate(
    { $group : { _id : { "companyauthemail" : "$companyauthemail", "email" : "$email" }, number : { $sum : 1 } } },
    { $group : { _id : "$_id.companyauthemail", number : { $sum : 1 } } }
    );
    

提交回复
热议问题