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

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.4.0-rc2
    • Affects Version/s: 2.4.0-rc1
    • Component/s: Write Ops
    • None
    • ALL

      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
      }
      

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

              Created:
              Updated:
              Resolved: