Skip to content

Instantly share code, notes, and snippets.

@artburkart
Last active May 4, 2016 00:03
Show Gist options
  • Save artburkart/a0c36ad28f0ec570c061dd152f5a3d93 to your computer and use it in GitHub Desktop.
Save artburkart/a0c36ad28f0ec570c061dd152f5a3d93 to your computer and use it in GitHub Desktop.
mongo-bookmark

Mongo Installation

  1. 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 update
sudo apt-get install -y mongodb-org
  1. Verify that your instance is up and running
mongo
  1. Set up an auth user with the following command:
use admin
db.createUser(
  {
    user: "<some-user>",
    pwd: "<some-password>",
    roles: [ { role: "userAdmin", db: "yourappsdb" } ]
  }
)
  1. 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
  1. Restart mongo
sudo service mongod restart
  1. To make it easier to log in as root, you can make a ~/.mongorc.js file:
db.auth('<some-user>', '<some-password>');
  1. Log into the db as root
mongo --port some-nondefault-port admin
  1. Create a user for your application
use yourappsdb
db.createUser(
  {
    user: "<some-other-user>",
    pwd: "<some-other-password>",
    roles: [ { role: "readWrite", db: "yourappsdb" } ]
  }
)
  1. Log in as the new user
mongo --port some-nondefault-port --host localhost -u <some-other-user> --authenticationDatabase admin -p
  1. 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment