Config

User created called mongodb, as you can see in /etc/passwd (list of all users).

$ cat /etc/passwd | grep mongodbmongodb:x:125:65534::/var/lib/mongodb:/bin/false

/var/lib/mongodb - data directory

/var/log/mongodb - log directory

/etc/mongodb.conf - configuration file

Here’s what’s in it.

$ cat /etc/mongodb.conf
# mongodb.conf
# Where to store the data.
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
bind_ip = 127.0.0.1
#port = 27017
# Enable journaling, <http://www.mongodb.org/display/DOCS/Journaling>
journal=true
# .......
# there's much more here but it looks like
# ^^this is the important stuff for now

Running

Start the service like this.

$ sudo service mongod start

Now it’s running (notice it’s using the config file):

$ ps ax | grep mongod
856 ?        Ssl    0:07 /usr/bin/mongod --config /etc/mongodb.conf
5162 pts/1    S+     0:00 grep --color=auto mongod

You can also use stop and restart. Cool.

Shell Commands

To start the mongo shell locally, check the mongod service is running and then run:

$ mongo
MongoDB shell version: 2.6.10
connecting to: test>

There are a bunch of ways of connecting to remote dbs and stuff but we’ll stick with this for now.

Here are some frickin’ commands.