定义
passwordPrompt()Prompts for the password in
mongosh. The entered password is not displayed in the shell. UsepasswordPrompt()in conjunction with methods that accept password as a parameter instead of specifying the password in cleartext to those methods.
示例
将 passwordPrompt() 与 db.createUser() 结合使用
db.createUser()要求指定密码。
You can use passwordPrompt() as the value for the pwd instead of specifying the password.
db.createUser( { user:"user123", pwd: passwordPrompt(), // Instead of specifying the password in cleartext roles:[ "readWrite" ] } )
根据提示输入密码。
将 passwordPrompt() 与 db.auth() 结合使用
When you run the db.auth(<username>, <password>) command you can replace the password with the passwordPrompt() method.
如果省略 db.auth(<username>, <password>) 命令中的密码,系统将提示用户输入密码。
以下示例提示用户输入未显示在shell中的密码:
db.auth("user123")
将 passwordPrompt() 与 db.changeUserPassword() 结合使用
db.changeUserPassword()要求指定密码。
You can use passwordPrompt() instead of specifying the password.
db.changeUserPassword("user123", passwordPrompt())
根据提示输入密码。
将 passwordPrompt() 与 db.updateUser() 结合使用
使用db.updateUser()更改密码时,该方法要求指定密码。
You can use passwordPrompt() as the value for the pwd instead of specifying the password.
db.updateUser( "user123", { pwd: passwordPrompt(), mechanisms: [ "SCRAM-SHA-256" ] } )
根据提示输入密码。