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

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      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. 

            Assignee:
            Danny Hatcher (Inactive)
            Reporter:
            Ashish
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: