db.table.aggregate([ { "$group": { _id: {slug: "$slug"}, slugs: { $addToSet: "$_id" } , count: { $sum : 1 } } }, { "$match": { count: { "$gt": 1 } } } ]).forEach(function(doc) { doc.slugs.shift(); db.table.remove({ _id: {$in: doc.slugs} }); })