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()
—
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()
—
I was able to reproduce this in version 1.8.1.
Cheers,
Leif