MongoDB

MongoDB is an open source document-oriented database.

Warning

WebFaction servers less than Web300 or less than Dweb89 only support the 32-bit version of MongoDB. The 32-bit version of MongoDB is limited to storing approximately 2.5GB of data. For more information on this limitation, please see the MongoDB blog article “32 bit limitations.”

Installing MongoDB

To install MongoDB:

  1. Create a custom application to make a directory and receive a port assignment for your MongoDB installation.

    1. Log in to the control panel.
    2. Click Domains / websites ‣ Applications. The list of applications appears.
    3. Click the Add new application button. The Create a new application form appears.
    4. In the Name field, enter a name for the application.
    5. In the App Category menu, click to select Custom.
    6. In the App Type menu, click to select Custom app (listening on port).
    7. If applicable, in the Machine menu, click to select a web server.
    8. Click the Save button. The application is created and added to the list of applications.
    9. Make a note of the application’s port number. It is required in a later installation step.
  2. Open an SSH session to your account.

  3. Install MongoDB.

    1. Switch to the MongoDB application directory. Enter cd $HOME/webapps/application, where application is the name of the MongoDB application as it appears on the control panel, and press Enter.

    2. Download the MongoDB Linux archive. Enter wget url, where url is the download URL for MongoDB, and press Enter.

      See the MongoDB downloads page for download URLs. If you’re using a server less than Web300 or less than Dweb89, choose the Linux 32-bit download URL. If you’re using any other server, choose the Linux 64-bit download URL.

      An archive, named mongodb-linux-architecture-version.tgz where architecture is x86_64 or i686 and version is the MongoDB version number, is created in the current directory.

    3. Extract the contents of the archive. Enter tar -xzf mongodb-linux-architecture-version.tgz and press Enter. A new directory is created in the current directory that contains the MongoDB files.

  4. Configure MongoDB.

    1. Create a database data directory. Enter mkdir data and press Enter.

    2. Start the MongoDB database. Enter $HOME/webapps/application/mongodb-linux-architecture-version/bin/mongod --auth --dbpath $HOME/webapps/application/data/ --port number, where number is the port number provided by the control panel, and press Enter.

      Warning

      Always start MongoDB with the --auth switch to prevent unauthorized users from tampering with your data.

    3. Open a second SSH session to your account. Leave the first session with MongoDB running.

    4. In the second session, connect to the database. Enter $HOME/webapps/application/mongodb-linux-architecture-version/bin/mongo localhost:port/admin and press Enter. An interactive prompt (>) appears.

    5. Add an administrator user, which can be used to manage other users. Enter db.addUser({user: "<username>", pwd: "<password>", roles: ["userAdminAnyDatabase"]}), where <username> is the new administrator username of your choice and <password> is the new user’s password, and press Enter.

    6. Authenticate as the administrator user. Enter db.auth("username", "password"), where username is the administrator username you chose in the previous step and password is the user’s password, and press Enter. If authentication is successful, a 1 appears.

      You can use this administrator user to manage other users and their permissions. See the MongoDB documentation’s on adding users for more detail.

      See also

      For more information about user authentication, see the MongoDB Authentication documentation.

    7. Close the database connection. Enter exit and press Enter. You may also end the SSH session.

The database is configured and ready. You may start and stop the database as needed.

To start the database, run $HOME/webapps/application/mongodb-linux-architecture-version/bin/mongod --auth --dbpath $HOME/webapps/application/data/ --port number.

To stop MongoDB while it is running in the foreground, press Ctrl + C. For other ways to stop the database, see the MongoDB Stopping mongod documentation.

See also

To learn more about using MongoDB, please see the MongoDB tutorial documentation. To learn more about using your preferred programming language with MongoDB, please see the MongoDB drivers list.

Previous topic

mod_wsgi

Next topic

Movable Type

Search the documentation

Example: "configure email" or "create database"

Feedback

Send us your feedback on this documentation.