$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(
{
'$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' =>
,
},
);
It would be great if it could work the same...