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

      Remove Duplicate Entries from MongDB Collection

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion mongodb nosql aggregate
      3
      1 Votes
      3 Posts
      805 Views
      bbigfordB

      @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.

    • scottalanmillerS

      Find Duplicate Value Entries in MongoDB Collection

      Watching Ignoring Scheduled Pinned Locked Moved IT Discussion mongodb nosql javascript aggregate
      2
      3 Votes
      2 Posts
      6k Views
      scottalanmillerS

      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 }}}])
    • 1 / 1