$addToSet and $each with an array does not filter duplicates for new field.

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • 2.1.0
    • Affects Version/s: 1.8.1
    • Component/s: Write Ops
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I am not sure if this is a regression or if the original bug SERVER-2249 was not fixed completely.

      If the field already exists then the duplicates are correctly filtered.

      db.test.insert({_id:"test_add_to_set",arr:[]})
      db.test.update({_id:"test_add_to_set"}, {$addToSet:{arr:{$each:[1,1]}}})
      db.test.find()

      { "_id" : "test_add_to_set", "arr" : [ 1 ] }

      If, however, the field is new then all of the values are added.

      db.test.insert({_id:"test_add_to_set"})
      db.test.update({_id:"test_add_to_set"}, {$addToSet:{arr:{$each:[1,1]}}})
      db.test.find()

      { "_id" : "test_add_to_set", "arr" : [ 1, 1 ] }

      I was able to reproduce this in version 1.8.1.

      Cheers,
      Leif

              Assignee:
              Tony Hannan (Inactive)
              Reporter:
              Leif Mortenson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: