mongodb 查重与去重
-- 查询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}}); })
本文来自博客园,作者:咔咔皮卡丘,转载请注明原文链接:https://www.cnblogs.com/anquing/p/17634830.html

浙公网安备 33010602011771号