Skip to content

Instantly share code, notes, and snippets.

@RemeJuan
Created May 18, 2017 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RemeJuan/f7f75c19a98fe41d021c982e03c18708 to your computer and use it in GitHub Desktop.
Save RemeJuan/f7f75c19a98fe41d021c982e03c18708 to your computer and use it in GitHub Desktop.
Mongo find all duplicated by 'name'
db.getCollection('events').aggregate([
{$group:{"_id":"$name","name":{$first:"$name"},"count":{$sum:1}}},
{$match:{"count":{$gt:1}}},
{$project:{"name":1,"_id":0}},
{$group:{"_id":null,"duplicateNames":{$push:"$name"}}},
{$project:{"_id":0,"duplicateNames":1}}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment