Created
August 27, 2018 09:49
-
-
Save nurfarazi/90252cb1e981a82acdc5f9373da2de60 to your computer and use it in GitHub Desktop.
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.usersProject.aggregate([ | |
{ | |
"$group": { | |
_id: {projectId: "$projectId"}, | |
dups: { $addToSet: "$_id" } , | |
count: { $sum : 1 } | |
} | |
}, | |
{ | |
"$match": { | |
count: { "$gt": 1 } | |
} | |
} | |
]).forEach(function(doc) { | |
doc.dups.shift(); | |
db.usersProject.remove({ | |
_id: {$in: doc.dups} | |
}); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment