[SERVER-15589] Do not allow creating inserted doc from update with dotted _id path sources Created: 09/Oct/14  Updated: 06/Dec/22  Resolved: 26/Feb/16

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Scott Hernandez (Inactive) Assignee: Backlog - Query Team (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Backwards Compatibility: Fully Compatible
Participants:

 Description   

For the following update (which results in an insert) this should not be allowed because it produces a document without constant _id field ordering:

db.a.update({"_id.a":1, "_id.b":2}, {$inc:{x:1}}, {upsert:true})
db.a.find()
{_id:{a:1, b:2}, x:1}
db.a.remove({})
db.a.update({"_id.b":1}, {$inc:{x:1}, $setOnInsert:{"_id.a":2}}, {upsert:true})
db.a.find()
{_id:{b:1,a:2}, x:1}



 Comments   
Comment by James Wahlin [ 26/Feb/16 ]

This is has been fixed both in 3.2.3 and 3.3.2:

replset:PRIMARY> db.a.drop()
true
replset:PRIMARY> db.a.update({"_id.a":1, "_id.b":2}, {$inc:{x:1}}, {upsert:true})
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 1,
	"nModified" : 0,
	"_id" : {
		"a" : 1,
		"b" : 2
	}
})
replset:PRIMARY> db.a.find()
{ "_id" : { "a" : 1, "b" : 2 }, "x" : 1 }
replset:PRIMARY> db.a.remove({})
WriteResult({ "nRemoved" : 1 })
replset:PRIMARY> db.a.update({"_id.b":1}, {$inc:{x:1}, $setOnInsert:{"_id.a":2}}, {upsert:true})
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 0,
	"nModified" : 0,
	"writeError" : {
		"code" : 66,
		"errmsg" : "After applying the update to the document {_id: { b: 1.0 } , ...}, the (immutable) field '_id' was found to have been altered to _id: { b: 1.0, a: 2.0 }"
	}
})
replset:PRIMARY> 

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