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

 posted on 2019-12-18 15:17  xibuhaohao  阅读(3203)  评论(0编辑  收藏  举报