[SERVER-12356] Error object is being returned to shell is displayed as [object Object] Created: 14/Jan/14  Updated: 11/Jul/16  Resolved: 16/Jan/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.5.4
Fix Version/s: 2.5.5

Type: Bug Priority: Major - P3
Reporter: Adam Comerford Assignee: Randolph Tan
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Testing done against 2.5.5-pre (built off master)

git version: cec1b16a90acadf97b892a56fb15943a72f04398

// insert a few objects like this one
> db.foo.findOne()
{ "_id" : ObjectId("52d4b437ec0439c7ad81e069"), "a" : 4 }
 
// multi update with $mul works on all 4
> db.foo.update({}, {$mul : {a : 2}}, false, true)
SingleWriteResult({
	"writeErrors" : [ ],
	"writeConcernErrors" : [ ],
	"nInserted" : 0,
	"nUpserted" : 0,
	"nUpdated" : 4,
	"nModified" : 4,
	"nRemoved" : 0,
	"upserted" : [ ]
})
// now insert a string
> db.foo.insert({a : "x"})
SingleWriteResult({
	"writeErrors" : [ ],
	"writeConcernErrors" : [ ],
	"nInserted" : 1,
	"nUpserted" : 0,
	"nUpdated" : 0,
	"nModified" : 0,
	"nRemoved" : 0,
	"upserted" : [ ]
})
// retry the update, expecting an error
> db.foo.update({}, {$mul : {a : 2}}, false, true)
SingleWriteResult({
	"writeErrors" : [
		[object Object]
	],
	"writeConcernErrors" : [ ],
	"nInserted" : 0,
	"nUpserted" : 0,
	"nUpdated" : 0,
	"nModified" : 0,
	"nRemoved" : 0,
	"upserted" : [ ]
})
// checking the previous error gives us the actual error
> db.getPrevError()
{
	"err" : "Cannot apply $mul to a value of non-numeric type. {_id: ObjectId('52d4b44eec0439c7ad81e06d')} has the field 'a' of non-numeric type String",
	"code" : 16837,
	"n" : 0,
	"nPrev" : 2,
	"ok" : 1
}

It's also worth noting that the nUpdated and nModified values are 0 when in fact the multiply operation was successful. Evidence:

> db.foo.find()
{ "_id" : ObjectId("52d4b437ec0439c7ad81e069"), "a" : 64 }
{ "_id" : ObjectId("52d4b43aec0439c7ad81e06a"), "a" : 48 }
{ "_id" : ObjectId("52d4b43cec0439c7ad81e06b"), "a" : 32 }
{ "_id" : ObjectId("52d4b43dec0439c7ad81e06c"), "a" : 16 }
{ "_id" : ObjectId("52d4b44eec0439c7ad81e06d"), "a" : "x" }
{ "_id" : ObjectId("52d4b63dec0439c7ad81e06e"), "a" : "y" }
> db.foo.update({}, {$mul : {a : 2}}, false, true)
SingleWriteResult({
	"writeErrors" : [
		[object Object]
	],
	"writeConcernErrors" : [ ],
	"nInserted" : 0,
	"nUpserted" : 0,
	"nUpdated" : 0,
	"nModified" : 0,
	"nRemoved" : 0,
	"upserted" : [ ]
})
// 0 modified or updated, but if we check the values again we can see the successful modification of the 4 numeric fields
> db.foo.find()
{ "_id" : ObjectId("52d4b437ec0439c7ad81e069"), "a" : 128 }
{ "_id" : ObjectId("52d4b43aec0439c7ad81e06a"), "a" : 96 }
{ "_id" : ObjectId("52d4b43cec0439c7ad81e06b"), "a" : 64 }
{ "_id" : ObjectId("52d4b43dec0439c7ad81e06c"), "a" : 32 }
{ "_id" : ObjectId("52d4b44eec0439c7ad81e06d"), "a" : "x" }
{ "_id" : ObjectId("52d4b63dec0439c7ad81e06e"), "a" : "y" }



 Comments   
Comment by Githook User [ 16/Jan/14 ]

Author:

{u'username': u'renctan', u'name': u'Randolph Tan', u'email': u'randolph@10gen.com'}

Message: SERVER-12356 Error object returned to shell is displayed as [object Object]
Branch: master
https://github.com/mongodb/mongo/commit/ab09662b279c8965005391350d8e56924533d128

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