db.changeUserPassword()
On this page本页内容
Definition定义
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.created
用户的数据库。Importantmongosh Method
This page documents a
mongosh
method. This is not the documentation for database commands or language-specific drivers, such as Node.js.For the database command, see the
updateUser
command.For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.
For the legacy
mongo
shell documentation, refer to the documentation for the corresponding MongoDB Server release:Parameter参数Type类型Description描述username
string The name of the user whose password you wish to change.要更改其密码的用户的名称。password
string The user's password. The value can be either:用户的密码。该值可以是:the user's password in cleartext string, or明文字符串中的用户密码,或passwordPrompt()
to prompt for the user's password.以提示输入用户的密码。
TipStarting in version 4.2 of the从mongo
shell, you can use thepasswordPrompt()
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.mongo
shell的4.2版本开始,您可以将passwordPrompt()
方法与各种用户身份验证/管理方法/命令结合使用来提示输入密码,而不是直接在方法/命令调用中指定密码。However, you can still specify the password directly as you would with earlier versions of the但是,您仍然可以像使用早期版本的mongo
shell.mongo
shell一样直接指定密码。writeConcern
document Optional.可选的。The level of write concern for the operation. See Write Concern Specification.操作的写入关注级别。请参阅写入关注规范。
Required Access所需访问权限
To modify the password of another user on a database, you must have the 若要修改数据库中其他用户的密码,必须对该数据库执行changePassword
action on that database.changePassword
操作。
Behavior行为
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 有关启用TLS传输加密的说明,请参阅为TLS/SSL配置mongod
and mongos
for TLS/SSL.mongod
和mongos
。
MongoDB does not store the password in cleartext. The password is only vulnerable in transit between the client and the server, and only if TLS transport encryption is not enabled.MongoDB不以明文形式存储密码。只有在客户端和服务器之间的传输过程中,并且只有在未启用TLS传输加密的情况下,密码才易受攻击。
Example实例
The following operation changes the password of the user named 以下操作将产品数据库中名为accountUser
in the products
database to SOh3TbYhx8ypJPxmt1oOfL
:accountUser
的用户的密码更改为SOh3TbYhx8ypJPxmt1oOfL
:
Starting in version 4.2 of the 从mongoshell的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一样直接指定密码。
use products
db.changeUserPassword("accountUser", passwordPrompt())
When prompted in 当在mongosh
for the password, enter the new password.mongosh
中提示输入密码时,请输入新密码。
You can also pass the new password directly to 您也可以将新密码直接传递给db.changeUserPassword()
:db.changeUserPassword()
:
use products
db.changeUserPassword("accountUser", "SOh3TbYhx8ypJPxmt1oOfL")