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

Update using runCommand is order sensitive in its command object fields

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.6.3
    • Shell
    • 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 }

    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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: