[SERVER-11197] $push error messages unclear Created: 15/Oct/13  Updated: 11/Jul/16  Resolved: 20/Nov/13

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

Type: Improvement Priority: Major - P3
Reporter: Amalia Hawkins Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: 26qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Related
related to SERVER-11366 improve new update() error strings Closed
Participants:

 Description   

{ "_id" : ObjectId("525847b17bb5149dea3bb07d"), "n" : 9, "x" : [  1 ] }
> db.foo.update({ n : 9}, {$push: {x: {$each: [{"a.b" : 1}]}}})
cannot use '$' in $each entries

This error message makes no sense. Should probably be "cannot use dotted fields in $each entries" or some such.

=======

> db.foo.update({ n : 9}, {$push: {x: {$each: [{a:1},{a:2}], $xxx: -1, $sort:{a:1}}}})
unrecognized clause is $push

Should be "in" not "is".

=======

> db.foo.update({ n : 9}, {$push: {x:{$each:[{a:1},{a:2}], $slice:-2.0, $sort:{a:1}, $sort:{a:1}}}})

According to db/ops/modifier_push_test.cpp line 463 this should ASSERT_NOT_OK but no error is thrown. Ditto duplicate $slice and duplicate $each.

=======

...will probably add more things here later...



 Comments   
Comment by Scott Hernandez (Inactive) [ 20/Nov/13 ]

All of this has already been changed in 2.5.4:

> db.foo.update({ n : 9}, {$push: {x: {$each: [{"a.b" : 1}]}}}, true)
...	"errmsg" : "a.b is not valid for storage.", ...
 
>  db.foo.update({ n : 9}, {$push: {x: {$each: [{a:1},{a:2}], $xxx: -1, $sort:{a:1}}}})
...	"errmsg" : "Unrecognized clause in $push: $xxx", ...
 

Unfortunately this is not testable in JS since it can't represent duplicate fields at the same level:

> update =  {$push: {x:{$each:[{a:1},{a:2}], $slice:-2.0, $sort:{a:1}, $sort:{a:1}}}}
{ "$push" : {
	"x" : {
		"$each" : [
			{ "a" : 1 },
			{ "a" : 2 }
		],
		"$slice" : -2,
		"$sort" : {
			"a" : 1
		}}}}
> db.foo.update({ n : 9},update)

Also, the push test seems fine (Note: our parser creates BSON which can contain repeated fields):

    TEST(Init, PushEachDuplicateSortClause) {
        const char* c = "{$push: {x:{$each:[{a:1},{a:2}], $slice:-2.0, $sort:{a:1}, $sort:{a:1}}}}";
        BSONObj modObj = fromjson(c);
        ModifierPush mod;
        ASSERT_NOT_OK(mod.init(modObj["$push"].embeddedObject().firstElement(),
                               ModifierInterface::Options::normal()));
    }

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