# 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 |
This comment has been minimized.
This comment has been minimized.
Thanks. To start over, I simply removed the admin db, i.e. Also, if you don't want to f**k with the 'mongo' command, you could name the alias something like 'mongoAdmin' |
This comment has been minimized.
This comment has been minimized.
Thanks a ton for this one. |
This comment has been minimized.
This comment has been minimized.
good |
This comment has been minimized.
This comment has been minimized.
Thank you - this is GOLD. |
This comment has been minimized.
This comment has been minimized.
how to connect dbs other than admin using super user ? |
This comment has been minimized.
This comment has been minimized.
thanks you!!!!!! :D |
This comment has been minimized.
This comment has been minimized.
Thanks! |
This comment has been minimized.
This comment has been minimized.
Thanks a lot... again saying it |
This comment has been minimized.
This comment has been minimized.
thanks it's very useful |
This comment has been minimized.
This comment has been minimized.
Thanks !!! |
This comment has been minimized.
This comment has been minimized.
Really useful! |
This comment has been minimized.
This comment has been minimized.
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!
|
This comment has been minimized.
This comment has been minimized.
Thank you! I'm new to nosql databases and just started with mongodb. Useful :D |
This comment has been minimized.
This comment has been minimized.
Thank you! |
This comment has been minimized.
This comment has been minimized.
Excellent, thank you . |
This comment has been minimized.
Lifesaver. Thank you!