[SERVER-17399] db.collection.update() upsert behavior change from 2.6 when query includes predicate on _id Created: 26/Feb/15  Updated: 27/Feb/15  Resolved: 27/Feb/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.0.0-rc11
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Michael Grundy Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 0
Labels: 28qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-14973 Support $eq with sharding Closed
is related to DOCS-4884 Document db.collection.update() behav... Closed
Operating System: ALL
Steps To Reproduce:

Given the following query and update objects:

 q={ "_id.hash" : "e6577bc7" }
 u={ "count" : 43.97}

If we run update, no upsert, no matches, no updates as expected:

> db.coll_name.update(q,u)
WriteResult({ "nMatched" : 0, "nUpserted" : 0, "nModified" : 0 })

If we make it an upsert it will fail (this is not the case in 2.6)

> db.coll_name.update(q,u,upsert=true)
WriteResult({
	"nMatched" : 0,
	"nUpserted" : 0,
	"nModified" : 0,
	"writeError" : {
		"code" : 111,
		"errmsg" : "field at '_id' must be exactly specified, field at sub-path '_id.hash'found"
	}
})

If we have a match for the query, it will succeed. Only the upsert behavior has changed.

q={ "_id.hash" : "e6577bc37" }
u={ "count" : 49.97}
> db.coll_name.update(q,u,upsert=true)
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })

Participants:

 Description   

In 2.6 a db.collection.update() upsert with a dotted path _id specification would complete successfully, in 3.0 this behavior has changed, though it is inconsistent between updates and upserts.

While this behavior is intentional (SERVER-14973), it may cause failures in applications that have inconsistent object notations.



 Comments   
Comment by Ramon Fernandez Marina [ 27/Feb/15 ]

michael.grundy@10gen.com, as you very well point out this is intentional behavior – but thanks for opening the ticket since it will help anyone who runs into this behavior find information about it.

Closing as "Works as designed" as per our live discussion.

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