Created
February 2, 2016 09:05
-
-
Save traumverloren/9c625b8d843a51d297bb to your computer and use it in GitHub Desktop.
Find duplicates in MongoDB collection using Aggregate in Rails Console
This file contains hidden or 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
results = Merchant.collection.aggregate([ | |
{ "$group" => { | |
_id: { "confirmation_token" => "$confirmation_token"}, | |
recordIds: {"$addToSet" => "$_id" }, | |
count: { "$sum" => 1 } | |
}}, | |
{ "$match" => { | |
count: { "$gt" => 1 } | |
}} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment