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.

  • You do not have permission to change user information (such as password). – nmad May 1 '14 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. – Meny Issakov Dec 15 '14 at 8:58
1

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

0

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, privacy policy and cookie policy

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