- Reference >
mongoShell 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 usernamestring Specifies an existing username with access privileges for this database. passwordstring Specifies the corresponding password. Alternatively, you can use
mongo --usernameand--passwordto specify authentication credentials.Returns: db.auth()returns0when authentication is not successful, and1when the operation is successful.