[SERVER-11366] improve new update() error strings Created: 24/Oct/13  Updated: 11/Jul/16  Resolved: 04/Dec/13

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

Type: Improvement Priority: Minor - P4
Reporter: David Storch Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Gantt Dependency
Related
related to SERVER-11623 Error message typos in modifier_push.cpp Closed
is related to SERVER-11188 update $bit error messages are unclear Closed
is related to SERVER-11197 $push error messages unclear Closed
Participants:

 Description   

> db.x.save({})
> db.x.update({}, {$set: {'a.b': 1}, $inc: {a: 1}})
Cannot apply $inc to a value of non-numeric type._id: ObjectId('52697da65d5cfc4b53b1838e') has the field a of non-numeric type Object

There should be a space before _id and the field name should be quoted, as shown below:

Cannot apply $inc to a value of non-numeric type. _id: ObjectId('52697da65d5cfc4b53b1838e') has the field 'a' of non-numeric type Object

Further error string improvements are described in the comments.



 Comments   
Comment by Githook User [ 04/Dec/13 ]

Author:

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

Message: SERVER-11188, SERVER-11366, SERVER-11384, SERVER-11623: Update message cleanup
Branch: master
https://github.com/mongodb/mongo/commit/a523a77c9601d3d8c1bd6175ead83702b95409b9

Comment by Amalia Hawkins [ 28/Oct/13 ]

Can we standardize the error message that occurs when multiple positional operators are found?

Right now, in $pullAll (and basically everywhere else) we have:

return Status(ErrorCodes::BadValue,
                     str::stream() << "Too many positional (i.e. '$') elements found in path '"
                                         << _fieldRef.dottedField() << "'");

but for $pop it's slightly different:

return Status(ErrorCodes::BadValue,
                      str::stream() << "Too many positional($) elements found in path '"
                                          << _fieldRef.dottedField() << "'");

Suggest changing $pop to match the rest.

Comment by David Storch [ 28/Oct/13 ]

1)

> db.x.update({}, {$addToSet: {a: {$each: 2}}})
The argument to $each in $addToSet must be an array but it was type of: NumberDouble

This should read "The argument to $each in $addToSet must be an array but it was of type NumberDouble".

2)

> db.x.update({}, {$push: {a: {$each: 2}}})
$each must be an array

This should read "The argument to $each in $push must be an array but it was of type NumberDouble".

3)

> db.x.update({a: 1}, {$pushAll: {a: {b: 1}}})
$pushAll requires an array of values but was given an embedded document, not an array.

I think we should improve this error string by removing the final "not an array" part, i.e. it should just be "$pushAll requires an array of values but was given an embedded document."

Comment by David Storch [ 25/Oct/13 ]

An error string related to the positional operator that could use improvement:

> db.x.insert([{arr: 1}, {arr: [1]}])
> db.x.find()
{ "_id" : ObjectId("526aa925b5d1bade7ded3d1b"), "arr" : 1 }
{ "_id" : ObjectId("526aa925b5d1bade7ded3d1c"), "arr" : [ 1 ] }
> db.x.update({arr: 1}, {$set: {"arr.$": 9}}, false, true)
matched field not provided

For some modifiers, such as $inc, the "matched field not provided string" was changed to "The positional operator did not find the match...". The old error string still exists, however, for $pull and $set:

modifier_pull.cpp
147:                return Status(ErrorCodes::BadValue, "matched field not provided");
 
modifier_set.cpp
146:                return Status(ErrorCodes::BadValue, "matched field not provided");

Comment by David Storch [ 25/Oct/13 ]

A few more of the error messages added here are missing single quotes when reporting field names, not just the $unset case above:

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