4

我在过去的某个时候使用 db.addUser(...) 创建了一个用户。我现在如何更改该用户的密码?

我使用具有 userAdmin 角色的用户登录。我用什么命令来更改另一个用户的密码?

编辑 2

我需要为 v2.4 样式的 addUser 和权限文档回答这个问题

编辑

有人建议我使用 2.2 addUser 语法来更改密码。这不起作用:

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

uncaught exception: couldn't add user: system.users entry must not have both 'roles' and 'readOnly' fields
4

3 回答 3

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

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

终于找到了!

于 2013-05-17T18:05:34.433 回答
1

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

于 2013-05-17T15:50:38.943 回答
1

要更改密码,只需addUser再次运行该命令。

db.addUser("coolguy",  "newxH@x0rPasswd", true);
于 2013-05-17T15:07:09.273 回答