Skip to content

Instantly share code, notes, and snippets.

@traumverloren
Created February 2, 2016 09:05
Show Gist options
  • Save traumverloren/9c625b8d843a51d297bb to your computer and use it in GitHub Desktop.
Save traumverloren/9c625b8d843a51d297bb to your computer and use it in GitHub Desktop.
Find duplicates in MongoDB collection using Aggregate in Rails Console
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