Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change my mongoDB user password as non administrator?

I understand I can change a user's password by running db.changeUserPassword() as an MongoDB administrator. However, as a user with no administrator privilege, can I change my password just with my own account?

Thanks,

Although solution provided by Gergo worked. But I had to create a new role in order for it to work. I thought changeOwnPassword should be a built in privilege and not require additional admin work. Creating a dedicated role just for the purpose to be able to change user's own password is overkill in MongoDB.

like image 276
johnsam Avatar asked Oct 15 '25 17:10

johnsam


1 Answers

If you have the necessary privileges, you can change your own password. You can verify that you have the necessary privileges by running this command:

db.runCommand(
  {
    usersInfo:"username",
    showPrivileges:true
  }
)

If it contains changeOwnPassword, then you can change the password:

db.runCommand(
    { updateUser: "username",
      pwd: "password"
    }
)

You can find more information in the MongoDB documentation.

like image 87
Gergo Erdosi Avatar answered Oct 17 '25 13:10

Gergo Erdosi