[SERVER-14771] Update using runCommand is order sensitive in its command object fields Created: 02/Aug/14  Updated: 11/Feb/15  Resolved: 17/Nov/14

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 2.6.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Kevin Willows Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Backwards Compatibility: Major Change
Operating System: ALL
Steps To Reproduce:

1. On any database execute the following command:

db.runCommand({updates:[{q:{name:"user1"},u:{$unset:{name:""}}}],update:"users"} )

will produce:

{
"ok" : 0,
"errmsg" : "no such cmd: updates",
"code" : 59,
"bad cmd" : {
        "updates" : [
                {
                        "q" : {
                                "name" : "user1"
                        },
                        "u" : {
                                "$unset" : {
                                        "name" : ""
                                }
                        }
                }
        ],
        "update" : "users"
}

Now reorder the fields:

db.runCommand({ update:"users", updates:[ {q:{name:"user1"},u:{$unset:{name:""}}}] })

Expected result for either condition:

{"ok" : 1, "nModified" : 1, "n" : 1 }

Participants:

 Description   

Doing an update using runCommand returns an error unless the first field in the command object is the command itself. update:<collection>

Is this by design?

Objects and JSON are intrinsically unordered so expecting fields in the command object to be in a specific order seems incongruous.

This is a blocking issue for sending commands over the wire as you cannot guarantee JSON field ordering. The only place you can garantee this is if you manually enter the commands in the shell.



 Comments   
Comment by Ramon Fernandez Marina [ 17/Nov/14 ]

This ticket was recently re-opened for re-evaluation. After some internal discussion we've come to the conclusion that making runCommand parameters order-insensitive would be a very large undertaking affecting both the server and drivers, would have some performance limitations, may require changes to the wire protocol, and may break existing applications.

We're therefore re-closing this ticket. Users looking for an API to runCommand that uses unordered hashes may consider requesting such feature in the relevant driver project (for example, see PERL-452).

Comment by Scott Hernandez (Inactive) [ 02/Aug/14 ]

This is how the command system is designed. All languages, including the javascript shell, support ordering for documents. BSON is ordered so the issue is only related to converting from the language constructs to BSON.

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