OPTIONS
翻译或纠错本页面

db.auth()

Definition

db.auth(username, password)

Allows a user to authenticate to the database from within the shell.

Parameter Type Description
username string Specifies an existing username with access privileges for this database.
password string Specifies the corresponding password.
mechanism string Optional. Specifies the authentication mechanism used. Defaults to MONGODB-CR. PLAIN is used for SASL/LDAP authentication, available only in MongoDB Enterprise.

Alternatively, you can use mongo --username, --password, and --authenticationMechanism to specify authentication credentials.

--authenticationMechanism supports additional mechanisms not available when using db.auth().

注解

The mongo shell excludes all db.auth() operations from the saved history.

返回:db.auth() returns 0 when authentication is not successful, and 1 when the operation is successful.
ON THIS PAGE