在 MongoDB 中为现有用户更改密码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16302417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Changing the password in MongoDB for existing user
提问by Srivatsa N
I have production environment where my mongoDB is up and running and DBAs are asking us to change the password which we use for authentication. One way to do this is run the addUser command again with a new password as described in change password
我有生产环境,我的 mongoDB 已启动并运行,DBA 要求我们更改用于身份验证的密码。一种方法是使用更改密码中所述的新密码再次运行 addUser 命令
> db.auth("app_user", "somepassword")
db.addUser("app_user", "new password")
This is as good as a adding a new user.
这与添加新用户一样好。
I understand that I have to restart mongod with the --auth option once I add a new user as described inbut as this is a production env and I can't restart my server. Is there any other option ? or if my approach is wrong how to change the password in mongoDB
我明白,我必须重新启动mongod的与--auth选项,一旦我添加一个新用户所描述的,但因为这是一个生产env和我不能重新启动我的服务器。还有其他选择吗?或者如果我的方法是错误的如何在 mongoDB 中更改密码
回答by Gabriel
For v2.4
对于 v2.4
db.changeUserPassword("app_user", "new password")
https://groups.google.com/d/msg/mongodb-user/KkXbDCsCfOs/rk2_h-oSbAwJhttps://jira.mongodb.org/browse/DOCS-1515
https://groups.google.com/d/msg/mongodb-user/KkXbDCsCfOs/rk2_h-oSbAwJ https://jira.mongodb.org/browse/DOCS-1515
回答by db80
MongoDB > 3.X
MongoDB > 3.X
db.updateUser("root", {pwd: "NewRootAdmin" })
Reference: https://docs.mongodb.com/manual/reference/method/db.updateUser/
参考:https: //docs.mongodb.com/manual/reference/method/db.updateUser/
回答by Asya Kamsky
You linked to a question asking about adding authentication to MongoDB which involves starting 'mongod' with option --auth. Since you are already running with --auth the restart is not necessary in your scenario.
您链接到一个关于向 MongoDB 添加身份验证的问题,该问题涉及使用 --auth 选项启动“mongod”。由于您已经使用 --auth 运行,因此在您的场景中不需要重新启动。
Just change the user password and you'll be set to go.
只需更改用户密码,您就可以开始了。
回答by ivanleoncz
Starting of Mongodb 4.0, you have to use db.updateUser()
, setting passwordDigestor
key as "server", when updating the user password:
从 Mongodb 4.0 开始,在更新用户密码时,您必须使用db.updateUser()
,将passwordDigestor
密钥设置为“服务器”: