mongo查询重复数据

db.getCollection('zhxHotelNotMatch').aggregate( {'$group':{

'_id': {'字段名': '$字段名'},

'uniqueIds': {'$addToSet': '$字段名'},

'count' : {'$sum': 1}

}},

{'$match': {

'count': {'$gt': 1}

}})

方式二:

db.holMidBaseInfoOne.aggregate(
{"$group" : { "_id": "$resPhone", "count": { "$sum": 1 } } },
{"$match": {"_id" :{ "$ne" : null } , "count" : {"$gt": 1} } },
{"$project": {"resPhone" : "$_id", "_id" : 0} }
)

原文地址:https://www.cnblogs.com/gun-a/p/13559044.html