Skip to content

Error messages when pushing to a table with position could be improved #2446

@sl-at-ibm

Description

@sl-at-ibm

When trying a $push update on a table but adding a $position directive, such as:

{"updateOne":{"options":{},"filter":{"Id":{"$eq":123}},"update":{"$push":{"StringArray":{"$each":["POS added 1"],"$position":1}}}}}

or

{"updateOne":{"options":{},"filter":{"Id":{"$eq":123}},"update":{"$push":{"StringArray":{"$each":["POS added A","POS added B"],"$position":1}}}}}

the error message could be more specific, at least say "extraneous $position field encountered". The message right now is too generic and probably a typical user would not be aware that $position works for collections but not for tables. Actually, they would probably try to use $position since 'it worked for collections'.

The command has invalid usage of $push operator, invalid usage of $each, $each value needs to be an array.

Update operator $push works for adding single element, combine $push with $each for adding multiple elements.

E.G.
Push single element to set/list. 
{"$push": {"listColumn": "value"}}
Push multiple elements to set/list. 
{"$push": {"listColumn": {"$each": ["value1","value2"]}}}
Push single entry to map.
{"$push": {"mapColumn": ["key1", "value1"]}} or {"$push": {"mapColumn": {"key1":"value1"}}}
Push multiple entries to map.
{"$push": {"mapColumn": {"$each": [["key1","value1"],["key2", "value2"]]}}} or {"$push": {"mapColumn": {"$each": [{"key1":"value1"},{"key2":"value2"}]}}}

Resend the command with valid usage of $push operator.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions