-
-
Save kmassada/2ef340a6c47dfea5a23d to your computer and use it in GitHub Desktop.
Mongo User setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment