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

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

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

      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:
            tonyh Tony Hannan
            Reporter:
            leif Leif Mortenson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: