MongoDB 实现多key group by 并实现 having

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} } }
)

原文地址:https://www.cnblogs.com/xibuhaohao/p/12060001.html