authenticate

On this page本页内容

authenticate

Authenticates using the x.509 authentication mechanism. 使用x.509身份验证机制进行身份验证。When using the mongo shell, use the db.auth() helper as follows:使用mongo shell时,请使用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. 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一样直接指定密码。

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

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

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

See

db.auth() and Security for more information.有关详细信息,请参阅db.auth()安全性

Behavior行为

Client Disconnection客户端断开

Starting in MongoDB 4.2, if the client that issued the authenticate disconnects before the operation completes, MongoDB marks the authenticate for termination (i.e. killOp on the operation).从MongoDB 4.2开始,如果发出authenticate的客户端在操作完成之前断开连接,MongoDB会将authenticate标记为终止(即操作上killOp)。