Skip to content

Instantly share code, notes, and snippets.

@git-ff
Created January 22, 2018 18:22
Show Gist options
  • Save git-ff/3f9d634933d19e2f421cba5874ee51c0 to your computer and use it in GitHub Desktop.
Save git-ff/3f9d634933d19e2f421cba5874ee51c0 to your computer and use it in GitHub Desktop.

Revisions

  1. git-ff created this gist Jan 22, 2018.
    2 changes: 2 additions & 0 deletions main.txt
    Original 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] }) });