Configuring and Using Authentication with MongoDB

Copyright (c) 2016 by Ashley Willis.

Configuring

Connecting with the MongoDB shell

After connecting with the mongo shell, you can authenticate against the authentication database via:

use admin
db.auth(user, password)

You can also also pass mongo the following options and the shell will prompt for the password. --authenticationDatabase is only needed if the authentication database is different from the database you want to use.

mongo -u $USER -p --authenticationDatabase $AUTH_DB $HOST/$DATABASE

Connecting with the MongoDB perl driver