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

$setOnInsert should not create an empty parent object when it should be a no op

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • 2.4.0-rc1
    • 2.4.0-rc2
    • Write Ops
    • None
    • ALL

    Description

      If $setOnInsert has dontApply == true, it should probably bail out early from _appendNewFromMods like the rename mods:

              case Mod::RENAME_FROM:
              case Mod::RENAME_TO:
                  if (modState.dontApply) {
                      return;
                  }

      Test

      c = db.c;
      c.drop();
       
      c.save( { a:1 } );
      c.update( {}, { $setOnInsert:{ 'b.c':1 }, $set:{ d:1 } } );
      printjson( c.findOne() );

      Output

      {
      	"_id" : ObjectId("5127d71b69c410f31b5f2ef1"),
      	"a" : 1,
      	"b" : {          // <-- There should not be a 'b' field here.
      		
      	},
      	"d" : 1
      }

      Attachments

        Activity

          People

            alerner Alberto Lerner
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: