ML
    • Register
    • Login
    • Search
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    1. Home
    2. Tags
    3. aggregate
    Log in to post
    • All categories
    • scottalanmiller

      Remove Duplicate Entries from MongDB Collection
      IT Discussion • mongodb nosql aggregate • • scottalanmiller

      3
      1
      Votes
      3
      Posts
      441
      Views

      bbigford

      @scottalanmiller said in Remove Duplicate Entries from MongDB Collection:

      You can add an index as well, to avoid having duplicates occur in the future:

      db.myCollection.createIndex({"my_field_to_be_unique":1},{unique:true})

      Good idea.

    • scottalanmiller

      Find Duplicate Value Entries in MongoDB Collection
      IT Discussion • mongodb nosql javascript aggregate • • scottalanmiller

      2
      3
      Votes
      2
      Posts
      5958
      Views

      scottalanmiller

      For more detail, showing the UIDs of each of the duplicates in question, try this little extension:

      db.myCollection.aggregate([ {$group: { _id: "$field_to_search", "dups": { "$push": "$_id" }, count: { $sum: 1}}}, {$match: { count: { $gt: 1 }}}])