MongoDB Aggregation: Counting distinct fields

前端 未结 8 2240
礼貌的吻别
礼貌的吻别 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:31

    An example

    db.collection.distinct("example.item").forEach( function(docs) {
        print(docs + "==>>" + db.collection.count({"example.item":docs}))
    });
    

提交回复
热议问题