Docs HomeMongoDB Manual

authenticate

On this page本页内容

authenticate

Authenticates using the x.509 authentication mechanism. 使用x.509身份验证机制进行身份验证。When using mongosh, use the db.auth() helper as follows:使用mongosh时,请按如下方式使用db.auth()帮助程序:

Tip

Starting in version 4.2 of the 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. 从mongoshell的4.2版本开始,您可以将passwordPrompt()方法与各种用户身份验证/管理方法/命令结合使用来提示输入密码,而不是直接在方法/命令调用中指定密码。However, you can still specify the password directly as you would with earlier versions of the mongo shell.但是,您仍然可以像使用早期版本的mongoshell一样直接指定密码。

db.auth( "username", passwordPrompt() )

In earlier versions, to use the db.auth() method, specify the password:在早期版本中,要使用db.auth()方法,请指定密码:

db.auth( "username", "password" )
Tip

See: 请参阅:

Behavior行为

Client Disconnection客户端断开连接

Starting in MongoDB 4.2, if the client that issued authenticate disconnects before the operation completes, MongoDB marks authenticate for termination using killOp.从MongoDB 4.2开始,如果在操作完成之前发出authenticate的客户端断开连接,MongoDB将使用killOp标记authenticate以终止。