On this page本页内容
db.
changeUserPassword
(username, password)¶Updates a user’s password. 更新用户的密码。Run the method in the database where the user is defined, i.e. the database you 在已定义用户的数据库,即创建用户的数据库中运行该方法。created
the user.
username |
string | |
password |
string |
Tip
|
writeConcern |
document | writeConcern document takes the same fields as the getLastError command.writeConcern 文档采用与getLastError 命令相同的字段。 |
To modify the password of another user on a database, you must have the 要修改数据库中其他用户的密码,必须对该数据库执行changeAnyPassword
action on that database.changeAnyPassword
操作。
Warning
By default, 默认情况下,db.changeUserPassword()
sends all specified data to the MongoDB instance in cleartext, even if using passwordPrompt()
. db.changeUserPassword()
将所有指定的数据以明文形式发送到MongoDB实例,即使使用passwordPrompt()
。Use TLS transport encryption to protect communications between clients and the server, including the password sent by 使用TLS传输加密来保护客户端和服务器之间的通信,包括db.changeUserPassword()
. db.changeUserPassword()
发送的密码。For instructions on enabling TLS transport encryption, see Configure mongod and mongos for TLS/SSL.有关启用TLS传输加密的说明,请参阅为TLS/SSL配置mongod
和mongos
。
MongoDB does not store the password in cleartext. MongoDB不以明文形式存储密码。The password is only vulnerable in transit between the client and the server, and only if TLS transport encryption is not enabled.只有在客户端和服务器之间传输时,并且只有在未启用TLS传输加密的情况下,密码才有漏洞。
The following operation changes the password of the user named 以下操作将accountUser
in the products
database to SOh3TbYhx8ypJPxmt1oOfL
:products
数据库中名为accountUser
的用户的密码更改为SOh3TbYhx8ypJPxmt1oOfL
:
Tip
Starting in version 4.2 of the 从mongo shell的4.2版开始,您可以将mongo
shell, you can use the passwordPrompt()
method in conjunction with various user authentication/management methods/commands to prompt for the password instead of specifying the password directly in the method/command call. passwordPrompt()
方法与各种用户身份验证/管理方法/命令结合使用,以提示输入密码,而不是直接在方法/命令调用中指定密码。However, you can still specify the password directly as you would with earlier versions of the 但是,您仍然可以像使用早期版本的mongo
shell.mongo
shell一样直接指定密码。
When prompted in the 当mongo shell提示输入密码时,请输入新密码。mongo
shell for the password, enter the new password.
You can also pass the new password directly to 还可以将新密码直接传递给db.changeUserPassword()
:db.changeUserPassword()
: