Use MongoDB to Store Application Data on Ubuntu 12.04

Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Deprecated

This guide has been deprecated and is no longer being maintained.

Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

MongoDB is a database engine that provides access to non-relational key-value databases. It is part of the growing NoSQL movement, which seeks to provide an alternative to traditional relational database management systems (RDBMS). In addition to its schema-free design and scalable architecture, MongoDB provides a JSON-based output format and specialized language specific bindings that make it particularly attractive for use in custom application development. Although MongoDB is a relatively new project, the software has been used in a number of large scale production deployments.

Before installing MongoDB, it is assume that you have followed our Setting Up and Securing a Compute Instance. If you are new to Linux server administration, you may be interested in our introduction to Linux concepts guide, beginner’s guide and administration basics guide.

Installing MongoDB

Make sure your package repositories and installed programs are up to date by issuing the following commands:

apt-get update
apt-get upgrade --show-upgraded

Enter the following command to install MongoDB server:

apt-get install mongodb-server

Configure MongoDB Server

By default, the configuration file for mongodb-server is located at /etc/mongodb.conf. Most of the settings are fairly self-explanatory and well-commented, but we’ve outlined some of the more important options below.

The dbpath option indicates where the database files will be stored (/var/lib/mongodb by default). The logpath directive indicates where MongoDB’s logs will be located (/var/log/mongodb/mongodb.log by default). logappend indicates whether or not new entries will be appended to the end of the log rather than overwriting existing log entries after each time MongoDB restarts.

The bind_ip option specifies which IP address(es) MongoDB should listen on. It is generally recommended to leave this at the default setting of 127.0.0.1 (localhost) unless you have a specific reason to host this DB to the public internet. Specifying 0.0.0.0 here will cause MongoDB to listen on all network interfaces. The port option in this file specifies the default port, but can be modified depending on your needs.

To provide additional security, it is recommended that you set the auth option to true in order to take advantage of MongoDB’s internal authentication capabilities. If you need to test the database without authentication, you can replace the auth option to noauth.

Please note that after making any changes to the MongoDB configuration file, you’ll always need to restart the service for the changes to take effect (see below).

Starting and Stopping the MongoDB Server

To start, restart, or stop MongoDB, issue the appropriate command from the following:

service mongodb start
service mongodb restart
service mongodb stop

Congratulations, you now have a fully functional installation of the MongoDB system.

Additional MongoDB Functionality

Now that MongoDB is running properly, you can begin to explore some of its features. Most interaction with MongoDB is done via the rich set of language-specific drivers. There are a number of tools that are installed by default that you might find useful for interacting with MongoDB databases. The mongo utility provides an interactive JavaScript shell for MongoDB including commands such as mongodump and mongorestore for creating and restoring backups and snapshots, as well as mongoexport and mongoimportjson for exporting individual collections in JSON format.

You can now fully enjoy application development with MongoDB!

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.