3

I had database level authentication in mongoDB, I had tried to change the password for existing user. It is throwing not authorized error.

Steps i followed to change the password

use wallet
db.auth("username","password")
db.changeUserPassword("username","newpassword");

Error

Changing password failed: not authorized for update on wallet.system.users at src/mongo/shell/db.js:186

Any suggestion will be grateful.

2
  • You do not have permission to change user information (such as password).
    – ek9
    Commented May 1, 2014 at 7:55
  • Does the user you're logged in with has the 'userAdmin' or 'userAdminAnyDatabase' role? If not, your user cannot alter other users information. Commented Dec 15, 2014 at 8:58

2 Answers 2

1

You need to login and use ADMIN database to perform the operation.

1

If you have changed security settings in Mongo configuration file you would not be able to change the password. To do so, set authorization to disabled:

Stop mongod service:

$ sudo service mongod stop

Open Mongo configuration file (paths may be different on your system):

Linux

Config file path: "/etc/mongod.conf"

Windows

Config file path: "C:\Program Files\MongoDB\Server\3.6\mongod.cfg"

Find authorization and set it to disabled:

security:
  authorization: enabled

change to:

security:
  authorization: disabled

Now start Mongo service:

$ sudo service mongod start

and change password from within Mongo shell:

> use mydb
> db.updateUser("myUser", {pwd: "myNewPassword" })

Now you can set authorization back to what it was. Just stop Mongo service, change settings and start service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.