- Follow these instructions to install mongo on 14.04.
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get install -y mongodb-org
- Verify that your instance is up and running
- Set up an auth user with the following command:
use admin
db.createUser(
{
user: "<some-user>",
pwd: "<some-password>",
roles: [ { role: "userAdmin", db: "yourappsdb" } ]
}
)
- Edit the
/etc/mongod.conf
file:
# Change the default port
net:
port: some-nondefault-port
bindIp: 127.0.0.1
# Enable auth
security:
authorization: enabled
- Restart mongo
sudo service mongod restart
- To make it easier to log in as root, you can make a
~/.mongorc.js
file:
db.auth('<some-user>', '<some-password>');
- Log into the db as root
mongo --port some-nondefault-port admin
- Create a user for your application
use yourappsdb
db.createUser(
{
user: "<some-other-user>",
pwd: "<some-other-password>",
roles: [ { role: "readWrite", db: "yourappsdb" } ]
}
)
- Log in as the new user
mongo --port some-nondefault-port --host localhost -u <some-other-user> --authenticationDatabase admin -p
- DISCLAIMER: I do not claim this is best practice. If you choose to follow
these steps, you do so AT YOUR OWN RISK. I am not responsible for any damage or
loss associated with these instructions or the use thereof.