- Reference >
mongo
Shell Methods >- Database Methods >
- db.auth()
db.auth()¶
On this page
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. Alternatively, you can use
mongo --username
and--password
to specify authentication credentials.Returns: db.auth()
returns0
when authentication is not successful, and1
when the operation is successful.