Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change a MongoDB user's password?

Tags:

mongodb

I used db.addUser(...) to create a user at some point in the past. How do I now change that user's password?

I logged in with a user with userAdmin role. What command do I use to change another user's password?

Edit 2

I need this answered for the v2.4 style addUser and privilege documents

  • http://docs.mongodb.org/manual/tutorial/add-user-to-database/
  • http://docs.mongodb.org/manual/reference/privilege-documents/

Edit

It has been suggested that I use the 2.2 addUser syntax to change the password. This does not work:

db.addUser({user: "test", pwd: "oldPassword", roles: ["readWrite"]})
db.addUser("test", "newPassword")

gives

uncaught exception: couldn't add user: system.users entry must not have both 'roles' and 'readOnly' fields
like image 506
Gabriel Avatar asked Dec 27 '22 03:12

Gabriel


2 Answers

db.changeUserPassword("test", "newPassword")

https://groups.google.com/d/msg/mongodb-user/KkXbDCsCfOs/rk2_h-oSbAwJ https://jira.mongodb.org/browse/DOCS-1515

Finally found it!

like image 84
Gabriel Avatar answered Jan 18 '23 00:01

Gabriel


To change a password, just run the addUser command again.

db.addUser("coolguy",  "newxH@x0rPasswd", true);
like image 38
chrsblck Avatar answered Jan 18 '23 00:01

chrsblck