[SERVER-2249] $addToSet with $each doesn't check uniqueness for new elements Created: 19/Dec/10  Updated: 12/Jul/16  Resolved: 19/Dec/10

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.7.3
Fix Version/s: 1.7.4

Type: Bug Priority: Major - P3
Reporter: David Cuadrado Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

linux ubuntu 10.10


Operating System: ALL
Participants:

 Description   

------------------------------------------------------------------------------
$ cat test_case.rb

require 'mongo'

db = Mongo::Connection.new.db('sample-db')
coll = db.collection('test')
coll.remove

coll.insert({:_id => "test_add_to_set", :arr => []})
coll.update({:_id => "test_add_to_set"}, {:$addToSet => {:arr => {:$each => [1,1,2,3]}}})

puts coll.find({:_id => "test_add_to_set"}).next_document.inspect

$ ruby test_case.rb

{"_id"=>"test_add_to_set", "arr"=>[1, 1, 2, 3]}

------------------------------------------------------------------------------

for some reason the value(1) in the array is repeated

is this a bug? or am I doing something wrong?



 Comments   
Comment by auto [ 19/Dec/10 ]

Author:

{u'login': u'erh', u'name': u'Eliot Horowitz', u'email': u'eliot@10gen.com'}

Message: fix case where the same element is in $each part of $addToSet SERVER-2249
https://github.com/mongodb/mongo/commit/aed49ae7154431ed505eadc9706e41513209ca7a

Comment by Scott Hernandez (Inactive) [ 19/Dec/10 ]

It looks like a bug. Here is a simpler repro.

> db.t.save({_id:1})
> db.t.update({_id:1},{$addToSet:{a:{$each:[1,1]}}})
> db.t.find()

{ "_id" : 1, "a" : [ 1, 1 ] }
Generated at Thu Feb 08 02:59:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.