Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-38805

Why there is no direct operator to find duplicates inside an array

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • Aggregation Framework
    • None
    • ALL

    Description

      I have below users collectionI have below users collection

          [{    "_id": 1,    "adds": ["111", "222", "333", "111"]    }, {    "_id": 2,    "adds": ["555", "666", "777", "555"]    }, {    "_id": 3,    "adds": ["888", "999", "000", "888"]    }]

      I need to find the duplicates inside the `adds` array
      The expected output should be 

          [{    "_id": 1,    "adds": ["111"]    }, {    "_id": 2,    "adds": [ "555"]    }, {    "_id": 3,    "adds": ["888"]    }]

      I have tried using many operators `$setUnion`, `$setDifference` but none of the did the trick. 

      Attachments

        Activity

          People

            daniel.hatcher@mongodb.com Danny Hatcher (Inactive)
            Ashishlal95 Ashish
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: