[SERVER-40461] WriteResult._id is undefined in case of upsert Created: 03/Apr/19  Updated: 29/Oct/23  Resolved: 26/Apr/19

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 4.0.6
Fix Version/s: 4.1.11

Type: Bug Priority: Major - P3
Reporter: Bruce Lucas (Inactive) Assignee: Gabriel Russell (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Dev Tools 2019-05-06, Dev Tools 2019-04-22
Participants:

 Description   

The WriteResult from an upsert displays in the shell like so:

res = db.c.update(..., ..., {upsert: true})
printjson(res)
{
	"nMatched" : 0,
	"nUpserted" : 1,
	"nModified" : 0,
	"_id" : ObjectId("5ca4b9271da31f1c4f6cc755")
}

However attempting to access the _id returns undefined:

printjson(res._id)
undefined

The returned _id can be accessed as res.getUpsertedId()._id, but the value printed for res and the documentation indicate that it should be available as res._id.



 Comments   
Comment by Githook User [ 24/Apr/19 ]

Author:

{'name': 'Benety Goh', 'username': 'benety', 'email': 'benety@mongodb.com'}

Message: SERVER-40461 fix lint
Branch: master
https://github.com/mongodb/mongo/commit/a5c727a27bd9b3a2b1f43190b9cb8e08812bd2f9

Comment by Githook User [ 24/Apr/19 ]

Author:

{'email': 'gabriel.russell@mongodb.com', 'name': 'Gabriel Russell', 'username': 'gabrielrussell'}

Message: SERVER-40461 implement WriteResult._id for upserts
Branch: master
https://github.com/mongodb/mongo/commit/e3e31d97772cca5d23a23180ceb9161fbf4e7736

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