On this page
Allows a user to authenticate to the database from within the shell.
db.auth()method can accept either:
the username and password.
a user document that contains the username and password, and optionally, the authentication mechanism and a digest password flag.
Parameter Type Description
string Specifies an existing username with access privileges for this database.
string Specifies the corresponding password.
Optional. Specifies the authentication mechanism used. Defaults to either:
SCRAM-SHA-1on new 3.0+ installations and on 3.0+ databases that have been upgraded from 2.6 with authSchemaUpgrade; or
As of MongoDB 3.6,
MONGODB-CRauthentication mechanism is deprecated. If you have not upgraded your
MONGODB-CRauthentication schema to SCRAM, see Upgrade to SCRAM.
For available mechanisms, see authentication mechanisms.
boolean Optional. Determines whether the server receives digested or undigested password. Set to false to specify undigested password. For use with SASL/LDAP authentication since the server must forward an undigested password to
0when authentication is not successful, and
1when the operation is successful.