Skip to content

Instantly share code, notes, and snippets.

@Kilerd
Created March 17, 2018 05:59
Show Gist options
  • Save Kilerd/65fc896bc29b52bfd4ab21869cfd0665 to your computer and use it in GitHub Desktop.
Save Kilerd/65fc896bc29b52bfd4ab21869cfd0665 to your computer and use it in GitHub Desktop.
mongo remove reciplicated data
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