1、group by多个key

db.testcol.aggregate(

    {"$group": {_id:{card:"$card",account:"$account"}, "count": { "$sum": 1 } } }

)

2、group by having实现

mongodb 实现group by 多个key having count(*) >1

db.testcol.aggregate(

    {"$group": {_id:{card:"$card",account:"$account"}, "count": { "$sum": 1 } } },

    {"$match": {"_id" :{ "$ne" : null } , "count" : {"$gt": 1} } }

)