[SERVER-8680] $setOnInsert should not create an empty parent object when it should be a no op Created: 22/Feb/13  Updated: 11/Jul/16  Resolved: 27/Feb/13

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.4.0-rc1
Fix Version/s: 2.4.0-rc2

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Alberto Lerner
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 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
}



 Comments   
Comment by auto [ 27/Feb/13 ]

Author:

{u'date': u'2013-02-27T03:27:12Z', u'name': u'Alberto Lerner', u'email': u'alerner@10gen.com'}

Message: SERVER-8680 $setOnInsert should not create an empty parent object when it should be a no op
Branch: master
https://github.com/mongodb/mongo/commit/73f277b1630c32339a90674428a7956c4f8b8bbf

Comment by Aaron Staple [ 22/Feb/13 ]

Oops - thanks!

Generated at Thu Feb 08 03:18:05 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.