if you're curious to know whether we've password option file concept in MongoDB something similar to MySQL (refer below links).
http://dev.mysql.com/doc/refman/5.1/en/password-security-user.html
http://stackoverflow.com/questions/16299603/mysql-utilities-my-cnf-option-file
With this, we can actually save credentials in a option hidden file within client session and we no need to enter the username and password every time. I know it's not secure way at times, but I require to skip this during my test cases and please note I can't disable my authentication as well.
Any JS/shell script/option file or thru config file works for me.
--------------------------------------------------------------------------------------------------------------------------------------------------------
Yes, you can specify a mongo JS script to run before running the shell that can authenticate your session. The format for the auth script would be:
db.getSiblingDB("<authentication database>").auth("<username>", "<password>");
The authentication database is the database where your user is defined - usually "admin". To use the auth script, invoke mongo with the --shell option and add the script name:
$ mongo --shell ./testauth.js
If you don't want an interactive shell, you can ommit the --shell option, and other scripts will also be authenticated as long as the auth script is the first one listed.
[host root @ myhostname ~] # cat ./.mongodbauth.js
db.getSiblingDB("admin").auth("admin_mongodb", "password")
[host root @ myhostname ~] #
[host root @ myhostname ~] # /opt/mongodb/bin/mongo --shell myhostname:37017 ./.mongodbauth.js -ssl
MongoDB shell version: 2.4.5
connecting to: myhostname:37017/test
type "help" for help
rs3:SECONDARY>
rs3:SECONDARY>
Anything you put in .mongorc.js in your home directory will be executed by the mongo shell on startup. You can also specify host and port information by re-assigning the db variable. An example .mongorc.js file could look like this:
db = connect("<hostname>:<port>/<database name>");
db.getSiblingDB("<authentication database>").auth("<username>", "<password>");
Ask Question
Hi, y’all