mongodb查询重复数据

db.getCollection('archive_person').aggregate( 
{'$group':{
        '_id': {'category': '$category'},
        'uniqueIds': {'$addToSet': '$_id'},
        'count' : {'$sum': 1}
    }},
    {'$match': {
        'count': {'$gt': 1}
    }}
)

category 替换为要查询的重复字段

 

posted @ 2020-09-08 17:42  谱写自己的人生  阅读(5613)  评论(0编辑  收藏  举报