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

the addUser shell helper should not mutate its arguments

    XMLWordPrintableJSON

Details

    • ALL
    • Hide

      2.6.0-rc1 shell, 2.4.9 server

      > userObj = {user:'bob', pwd:'a', roles:['read']}
      {
              "user": "bob",
              "pwd": "a",
              "roles": [
                      "read"
              ]
      }
      > db.addUser(userObj)
      WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
      Inserted 1 record(s) in 14ms
      Successfully added user: {
              "user": "bob",
              "roles": [
                      "read"
              ],
              "_id": ObjectId("5318d2f453c8583362580e4e")
      }
      > userObj
      {
              "user": "bob",
              "roles": [
                      "read"
              ],
              "_id": ObjectId("5318d2f453c8583362580e4e"),
              "pwd": "a"
      }
      > db.dropDatabase()
      { "dropped": "test", "ok": 1 }
      > db.addUser(userObj)
      WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
      2014-03-06T14:58:14.974-0500 Error: couldn't add user: no such cmd: _id at src/mongo/shell/db.js:1007

      Show
      2.6.0-rc1 shell, 2.4.9 server > userObj = {user:'bob', pwd:'a', roles:['read']} { "user": "bob", "pwd": "a", "roles": [ "read" ] } > db.addUser(userObj) WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead Inserted 1 record(s) in 14ms Successfully added user: { "user": "bob", "roles": [ "read" ], "_id": ObjectId("5318d2f453c8583362580e4e") } > userObj { "user": "bob", "roles": [ "read" ], "_id": ObjectId("5318d2f453c8583362580e4e"), "pwd": "a" } > db.dropDatabase() { "dropped": "test", "ok": 1 } > db.addUser(userObj) WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead 2014-03-06T14:58:14.974-0500 Error: couldn't add user: no such cmd: _id at src/mongo/shell/db.js:1007

    Description

      The addUser shell helper takes a document describing the user object. If it winds up writing that document directly to system.users (ie when talking to a pre-2.6 server), the doc gets an _id field added to it by the insert code. This makes re-using this document to re-create the user impossible without manually deleting the _id field. This is mainly a problem when testing, where a test may want to reuse the same user definitions multiple times.

      Attachments

        Activity

          People

            spencer@mongodb.com Spencer Brody (Inactive)
            matt.dannenberg Matt Dannenberg
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: