Created
January 22, 2018 18:22
-
-
Save git-ff/3f9d634933d19e2f421cba5874ee51c0 to your computer and use it in GitHub Desktop.
Revisions
-
git-ff created this gist
Jan 22, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ // https://www.compose.com/articles/finding-duplicate-documents-in-mongodb/ db.hotels.aggregate([{ $group: { _id: { hid: "$hid" }, uniqueIds: { $addToSet: "$_id" }, count: {$sum: 1} } }, {$match: {count: {"$gt": 1}}}, {$sort: {count: -1}} ]).forEach(function(doc){ db.hotels.remove({ _id: doc.uniqueIds[1] }) });