[SERVER-3245] $addToSet and $each with an array does not filter duplicates for new field. Created: 12/Jun/11  Updated: 12/Jul/16  Resolved: 22/Sep/11

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.8.1
Fix Version/s: 2.1.0

Type: Bug Priority: Major - P3
Reporter: Leif Mortenson Assignee: Tony Hannan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

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



 Comments   
Comment by auto [ 22/Sep/11 ]

Author:

{u'login': u'TonyGen', u'name': u'Tony Hannan', u'email': u'tony@10gen.com'}

Message: SERVER-3245: fix my previous commit
Branch: master
https://github.com/mongodb/mongo/commit/5bc9ef436a40c6002b4c9f1229c17aab96e01710

Comment by auto [ 22/Sep/11 ]

Author:

{u'login': u'TonyGen', u'name': u'Tony Hannan', u'email': u'tony@10gen.com'}

Message: SERVER-3245: $addToSet $each filter dups of new field
Branch: master
https://github.com/mongodb/mongo/commit/6a5bed92f5ba424b965f4c3552cd5dc2b0dc28ce

Generated at Thu Feb 08 03:02:31 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.