Created
March 17, 2018 05:59
-
-
Save Kilerd/65fc896bc29b52bfd4ab21869cfd0665 to your computer and use it in GitHub Desktop.
mongo remove reciplicated data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.comments_copy.aggregate([ | |
{ | |
$group: { _id: {mid: '$mid',content: '$content'},count: {$sum: 1},dups: {$addToSet: '$_id'}} | |
}, | |
{ | |
$match: {count: {$gt: 1}} | |
} | |
]).forEach(function(doc){ | |
doc.dups.shift(); | |
db.comments_copy.remove({_id: {$in: doc.dups}}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment