Definição
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.
Exemplos
Usar passwordPrompt() com db.createUser()
O db.createUser() requer uma senha para ser especificada.
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" ] } )
Digite a senha quando solicitado.
Usar passwordPrompt() com db.auth()
When you run the db.auth(<username>, <password>) command you can replace the password with the passwordPrompt() method.
Se você omitir a senha do comando db.auth(<username>, <password>), o usuário deverá digitar uma senha.
O exemplo a seguir solicita que o usuário insira uma senha que não é exibida no shell:
db.auth("user123")
Usar passwordPrompt() com db.changeUserPassword()
O db.changeUserPassword() requer uma senha para ser especificada.
You can use passwordPrompt() instead of specifying the password.
db.changeUserPassword("user123", passwordPrompt())
Digite a senha quando solicitado.
Usar passwordPrompt() com db.updateUser()
Ao alterar a senha com db.updateUser(), o método requer que uma senha seja especificada.
You can use passwordPrompt() as the value for the pwd instead of specifying the password.
db.updateUser( "user123", { pwd: passwordPrompt(), mechanisms: [ "SCRAM-SHA-256" ] } )
Digite a senha quando solicitado.