On this page本页内容
passwordPrompt
()¶New in version 4.2.版本4.2中的新功能。
Prompts for the password in the mongo
shell. The entered password is not displayed in the shell. Use passwordPrompt()
in conjunction with methods that accept password as a parameter instead of specifying the password in cleartext to those methods.
passwordPrompt()
with db.createUser()
¶The db.createUser()
requires a password to be specified.
Starting in MongoDB 4.2, you can use passwordPrompt()
as the value for the pwd
instead of specifying the password.
Enter the password when prompted.
passwordPrompt()
with db.auth()
¶Starting in MongoDB 4.2, when you run the db.auth(<username>, <password>) command you can replace the password with the passwordPrompt()
method.
Starting in MongoDB 4.4, if you omit the password from the db.auth(<username>, <password>) command, the user is prompted to enter a password.
Both of the following examples prompt the user to enter a password which is not displayed in the shell:
passwordPrompt()
with db.changeUserPassword()
¶The db.changeUserPassword()
requires a password to be specified.
Starting in MongoDB 4.2, you can use passwordPrompt()
instead of specifying the password.
Enter the password when prompted.
passwordPrompt()
with db.updateUser()
¶When changing the password with db.updateUser()
, the method requires a password to be specified.
Starting in MongoDB 4.2, you can use passwordPrompt()
as the value for the pwd
instead of specifying the password.
Enter the password when prompted.