[SERVER-630] $addToSet can cause upsert to fail Created: 12/Feb/10  Updated: 12/Jul/16  Resolved: 12/Feb/10

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 1.3.2
Fix Version/s: 1.3.3

Type: Bug Priority: Major - P3
Reporter: Andrew Bryan Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

$addToSet seems to cause an upsert to fail when the document doesn't exist (i.e. it fails to insert).

When using $push the document is correctly inserted. For example (perl):

$col->update(

{ '_id' => '123' },
{
'$push' => { 'tags' => 'foo' },
},
{ 'upsert' => 1, }
);

(where the document id 123 doesn't yet exist) creates:
{
_id => 123,
tags => [ 'foo' ],
}

which is nice! but the $addToSet equivalent fails to insert anything:

$col->update(
{ '_id' => '123' }

,
{
'$addToSet' =>

{ 'tags' => 'foo' }

,
},

{ 'upsert' => 1, }

);

It would be great if it could work the same...



 Comments   
Comment by auto [ 12/Feb/10 ]

Author:

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

Message: fix upsert with addToSet SERVER-630
http://github.com/mongodb/mongo/commit/a023fc861b1bcd3f3cd9e3723a8e97a743c53bd8

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