---
title: "Running MongoDB"
date: "2015-02-17"
category: "guides"
slug: "running-mongodb"
---

[MongoDB](http://www.mongodb.org/) is a document-oriented [NoSQL](http://en.wikipedia.org/wiki/NoSQL) database. It complements key-value stores like [[running-redis]] or Memcached and is suited for [different use cases](http://stackoverflow.com/questions/5400163/when-to-redis-when-to-mongodb). It is available on [[determining-platform-version]] (v6+) without [[compiling-programs]] from source. Accounts with [[is-terminal-access-available]] are eligible to use MongoDB.

## Quickstart

From the [[accessing-terminal]]:

1. Create a data directory:

    ```
    mkdir ~/mongodb
    ```

    This creates a `mongodb` directory in your [[home-directory-location]].

2. Start the server (replace `PORT` with a [[listening-ports]] assigned to your account):

    ```
    mongod --bind_ip 127.0.0.1 --port PORT --dbpath ~/mongodb --logpath ~/mongo.log --pidfilepath ~/mongodb.pid --fork
    ```

> **Note:** Binding to `127.0.0.1` restricts access to local traffic only. For [[running-node-js]] or [[setting-rails-passenger]] applications, you can use a UNIX socket instead: `--unixSocketPrefix /tmp/mongodb.sock` (omit `--bind_ip` and `--port`).

## Configuring and Daemonizing

Create a configuration file named `mongodb.conf` in your [[home-directory-location]] with the following content. Replace `PORT` with your assigned port and `/home/example` with your actual home directory path:

```
bind_ip = 127.0.0.1
port = PORT
fork = true
pidfilepath = /home/example/mongod.pid
logpath = /home/example/mongodb.log
dbpath = /home/example/mongodb
journal = true
nohttpinterface = true
```

### Creating the File with Vim

1. Run `vim ~/mongodb.conf`
2. Press `i` to enter Insert mode
3. Paste the configuration (CTRL+V, Shift+INS, or your terminal's paste shortcut)
4. Press **Esc**
5. Type `:wq` and press Enter

Start MongoDB with the configuration file:

```
mongod -f ~/mongodb.conf
```

### Starting on Server Boot

1. In the [[logging-into-the-control-panel]], navigate to **Dev** > **Task Scheduler**
2. Under **Command**, enter: `mongodb ~/mongodb.conf`
3. Under **Scheduling**, select **Server Start**
4. Click **Add**

## See Also

- MongoDB [documentation](http://docs.mongodb.org/manual/)
- [The Little MongoDB Book](http://openmymind.net/2011/3/28/The-Little-MongoDB-Book/)
