How to change MongoDB user password?

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

I logged in with a user with the userAdmin role. Which command can I use to change the password of another user?

Edit 2

I need this to respond to addUser files and v2.4 style privileges

Edit

It has been suggested that I use addUser syntax 2.2 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 
+4
source share
3 answers
+5
source

To change the password, just run the addUser command.

 db.addUser("coolguy", " newxH@x0rPasswd ", true); 
+1
source

may I help.

Worrying about the argument passed. This is for the readOnly parameter.

EDIT: Steps I followed: added a new user

 > db.addUser("admin","firstpwd") { "user" : "admin", "readOnly" : false, "pwd" : "40a84fcba954c8924d277f23b0f880b1", "_id" : ObjectId("51966ec8c7ad876ba0319438") } 

Output

 > db.auth("admin","firstpwd") 1 

change Password

 > db.addUser("admin","secondpwd") { "_id" : ObjectId("51966ec8c7ad876ba0319438"), "user" : "admin", "readOnly" : false, "pwd" : "82f4e416844349418281a3eca1cf6082" } 

Output

db.auth ("admin", "secondpwd") 1

MongoDB Shell Version: 2.4.3

0
source

Source: https://habr.com/ru/post/1481411/


All Articles