Reputation: 1751
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
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
Upvotes: 4
Views: 13881
Reputation: 1751
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!
Upvotes: 8
Reputation: 2321
this might help.
Becareful about the argument passed. That is for readOnly option.
EDIT : Steps I followed in : Added a new user
> db.addUser("admin","firstpwd")
{
"user" : "admin",
"readOnly" : false,
"pwd" : "40a84fcba954c8924d277f23b0f880b1",
"_id" : ObjectId("51966ec8c7ad876ba0319438")
}
exit
> db.auth("admin","firstpwd")
1
Changing the password
> db.addUser("admin","secondpwd")
{
"_id" : ObjectId("51966ec8c7ad876ba0319438"),
"user" : "admin",
"readOnly" : false,
"pwd" : "82f4e416844349418281a3eca1cf6082"
}
exit
db.auth("admin","secondpwd") 1
MongoDB shell version: 2.4.3
Upvotes: 1
Reputation: 4088
To change a password, just run the addUser
command again.
db.addUser("coolguy", "newxH@x0rPasswd", true);
Upvotes: 1