-- 查询image重复记录 db.getCollection('image').aggregate([ { $group: { _id : {imageId: '$imageId',time:'$time'}, count: { $sum : 1 } } }, { $match: { count: { $gt : 1} } } ]) -- 删除image重复记录 db.getCollection('image').aggregate([ { $group: { _id : {imageId:'$imageId'}, count: { $sum : 1 }, dups:{$addToSet:'$_id'} } }, { $match: { count: { $gt : 1} } } ]).forEach(function(doc){ doc.dups.shift(); db.image.remove({_id:{$in:doc.dups}}); }) -- 查询face重复记录 db.getCollection('face').aggregate([ { $group: { _id : {faceId: '$faceId',time:'$time',personId:'$personId'}, count: { $sum : 1 } } }, { $match: { count: { $gt : 1} } } ]) -- 删除face重复记录 db.getCollection('face').aggregate([ { $group: { _id : {faceId: '$faceId',time:'$time',personId:'$personId'}, count: { $sum : 1 }, dups:{$addToSet:'$_id'} } }, { $match: { count: { $gt : 1} } } ], {allowDiskUse: true} ).forEach(function(doc){ doc.dups.shift(); db.face.remove({_id:{$in:doc.dups}}); })
标签:查重,count,dups,mongodb,time,db,doc,id From: https://www.cnblogs.com/anquing/p/17634830.html