Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-630

$addToSet can cause upsert to fail

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • 1.3.3
    • 1.3.2
    • Write Ops
    • None

    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...

      Attachments

        Activity

          People

            eliot Eliot Horowitz (Inactive)
            abryan17 Andrew Bryan
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: