-
-
Save tamoyal/10441108 to your computer and use it in GitHub Desktop.
# Create your superuser | |
$ mongo | |
> use admin | |
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]}) | |
> exit | |
# Alias for convenience (optional and at your own risk) | |
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile | |
$ source ~/.bash_profile | |
# Add user to your DB | |
$ mongo | |
> use some_db | |
> db.createUser( | |
{ | |
user: "mongouser", | |
pwd: "someothersecret", | |
roles: ["readWrite"] | |
} | |
) | |
# If you get locked out, start over | |
sudo service mongod stop | |
sudo mv /data/admin.* . # for backup | |
sudo service mongod start |
Thanks.
To start over, I simply removed the admin db, i.e. sudo rm /data/admin.*
Also, if you don't want to f**k with the 'mongo' command, you could name the alias something like 'mongoAdmin'
Thanks a ton for this one.
good
Thank you - this is GOLD.
how to connect dbs other than admin using super user ?
thanks you!!!!!! :D
Thanks!
Thanks a lot... again saying it
thanks it's very useful
Thanks !!!
Really useful!
Thx mate :)
If you put the '-p' option at the end of the command line without a password then the client will prompt you for it interactively. Seems a bit more prudent than leaving that password sitting in your bash profile in plaintext!
echo 'alias mongo="mongo --port 27017 -u someadmin --authenticationDatabase admin -p"' >> ~/.bash_profile
Thank you! I'm new to nosql databases and just started with mongodb. Useful :D
Thank you!
Excellent, thank you .
Lifesaver. Thank you!