Use MongoDB to Store Application Data on Ubuntu 12.04 (Precise)
Updated by Linode
This guide has been deprecated and is no longer being maintained.
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 getting started guide. 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.
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.
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.
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
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:
1 2 3
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
mongorestore for creating and restoring backups and snapshots, as well as
mongoimportjson for exporting individual collections in JSON format.
You can now fully enjoy application development with MongoDB!
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.
- MongoDB Project
- Language-Specific MongoDB Drivers
- MongoDB Shell
- MapReduce Paradigm and MongoDB
- MongoDB Sharding
- Configuration Parameters
- File Based Configuration
This guide is published under a CC BY-ND 4.0 license.