[SERVER-1351] GLE upserted _id field should always be filled in Created: 02/Jul/10  Updated: 27/Oct/15  Resolved: 11/Oct/13

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

Type: Improvement Priority: Major - P3
Reporter: Mathias Stearn Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 3
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File upsert1.js    
Issue Links:
Depends
is depended on by SERVER-2625 Mongo throws uncaught exception while... Closed
is depended on by DOCS-1951 Document: GLE upserted _id field shou... Closed
Related
is related to SERVER-13865 Shell returns incorrect WriteResult f... Closed
is related to SERVER-10302 Use new update framework to enforce p... Closed
is related to SERVER-1173 GetLastError After Upsert Should Incl... Closed
is related to SERVER-9958 $setOnInsert should allow _id to be set Closed
Participants:

 Description   

the id isn't included in at least two cases where it probably should for consistency

if the _id wasn't generated server-side:
> db.foo.update({_id:'asdf'}, {$set: {a:'123'}}, true)
> db.getLastErrorObj()

{ "err" : null, "updatedExisting" : false, "n" : 1, "ok" : true }

> db.foo.update(

{a:'asdf'}

, {_id: 'qwer'}, true)
> db.getLastErrorObj()

{ "err" : null, "updatedExisting" : false, "n" : 1, "ok" : true }

if the object already existed:

> db.foo.update({_id:{$gt: ObjectId("4c2e342e38535540224f7945")}}, {$set: {a:'123'}}, true)
> db.getLastErrorObj()

{ "err" : null, "updatedExisting" : false, "upserted" : ObjectId("4c2e346538535540224f7946"), "n" : 1, "ok" : true }

> db.foo.update({_id:{$gt: ObjectId("4c2e342e38535540224f7945")}}, {$set: {a:'123'}}, true)
> db.getLastErrorObj()

{ "err" : null, "updatedExisting" : true, "n" : 1, "ok" : true }

 Comments   
Comment by Scott Hernandez (Inactive) [ 11/Oct/13 ]

For the docs we need to remove any mention that we return only an ObjectId, if that is in the docs anywhere else.

Wrong info here:
http://docs.mongodb.org/manual/reference/command/findAndModify/

Comment by auto [ 11/Oct/13 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-1351: return new _id from inserted doc from update
Branch: master
https://github.com/mongodb/mongo/commit/80c79f8464d26ca128b2455a8e02c9882f8c4640

Comment by Scott Hernandez (Inactive) [ 27/Jul/13 ]

Updated jstests/upsert1.js which fails (on both old and new update code)

Generated at Thu Feb 08 02:56:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.