Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-14771

Update using runCommand is order sensitive in its command object fields

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.3
    • Component/s: Shell
    • Labels:
      None
    • Major Change
    • ALL
    • Hide

      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 }
      
      Show
      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 }

      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.

            Assignee:
            ramon.fernandez@mongodb.com Ramon Fernandez Marina
            Reporter:
            synaptek Kevin Willows
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: