Created
May 18, 2017 05:19
-
-
Save RemeJuan/f7f75c19a98fe41d021c982e03c18708 to your computer and use it in GitHub Desktop.
Mongo find all duplicated by 'name'
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.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