I am running mongo 2.2.2 on osx.
When I do the following authentication is going fine:
$ mongo
>> use admin
>> db.auth(\"uname\", \"passw
This is the way to access an authenticate MongoDB database from terminal
mongo -u user_name -p "your_password" host_name/database_name
Ex:
mongo -u hasib -p "123456" localhost/my_db
To Login to MongoDB Via Command Line do the following
$ mongo admin -u 'username' -p 'Password'
A password containing special characters, especially the dollar sign, has to be put in single quotes to protect them from the command shell:
$ mongo admin -u uname -p 'password'
You have to user the --authenticationDatabase
to indicate mongodb where to find the user you have created. For example:
mongo admin -u uname -p 'password' --authenticationDatabase admin