5. MongoDB Documentation, Release 2.6.4
See About MongoDB Documentation (page 811) for more information about the MongoDB Documentation project,
this Manual and additional editions of this text.
Note: This version of the PDF does not include the reference section, see MongoDB Reference Manual1 for a PDF
edition of all MongoDB Reference Material.
1http://docs.mongodb.org/master/MongoDB-reference-manual.pdf
Contents 1
7. CHAPTER 1
Introduction to MongoDB
Welcome to MongoDB. This document provides a brief introduction to MongoDB and some key concepts. See the
installation guides (page 5) for information on downloading and installing MongoDB.
1.1 What is MongoDB
MongoDB is an open-source document database that provides high performance, high availability, and automatic
scaling.
1.1.1 Document Database
A record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB docu-ments
are similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.
Figure 1.1: A MongoDB document.
The advantages of using documents are:
• Documents (i.e. objects) correspond to native data types in many programming languages.
• Embedded documents and arrays reduce need for expensive joins.
• Dynamic schema supports fluent polymorphism.
3
8. MongoDB Documentation, Release 2.6.4
1.1.2 Key Features
High Performance
MongoDB provides high performance data persistence. In particular,
• Support for embedded data models reduces I/O activity on database system.
• Indexes support faster queries and can include keys from embedded documents and arrays.
High Availability
To provide high availability, MongoDB’s replication facility, called replica sets, provide:
• automatic failover.
• data redundancy.
A replica set (page 503) is a group of MongoDB servers that maintain the same data set, providing redundancy and
increasing data availability.
Automatic Scaling
MongoDB provides horizontal scalability as part of its core functionality.
• Automatic sharding (page 607) distributes data across a cluster of machines.
• Replica sets can provide eventually-consistent reads for low-latency high throughput deployments.
4 Chapter 1. Introduction to MongoDB
9. CHAPTER 2
Install MongoDB
MongoDB runs on most platforms and supports both 32-bit and 64-bit architectures.
2.1 Installation Guides
See the Release Notes (page 725) for information about specific releases of MongoDB.
Install on Linux (page 6) Documentations for installing the official MongoDB distribution on Linux-based systems.
Install on Red Hat (page 6) Install MongoDB on Red Hat Enterprise, CentOS, Fedora and related Linux sys-tems
using .rpm packages.
Install on Ubuntu (page 9) Install MongoDB on Ubuntu Linux systems using .deb packages.
Install on Debian (page 12) Install MongoDB on Debian systems using .deb packages.
Install on Other Linux Systems (page 14) Install the official build of MongoDB on other Linux systems from
MongoDB archives.
Install on OS X (page 16) Install the official build of MongoDB on OS X systems from Homebrew packages or from
MongoDB archives.
Install on Windows (page 19) Install MongoDB on Windows systems and optionally start MongoDB as a Windows
service.
Install MongoDB Enterprise (page 24) MongoDB Enterprise is available for MongoDB Enterprise subscribers and
includes several additional features including support for SNMP monitoring, LDAP authentication, Kerberos
authentication, and System Event Auditing.
Install MongoDB Enterprise on Red Hat (page 24) Install the MongoDB Enterprise build and required depen-dencies
on Red Hat Enterprise or CentOS Systems using packages.
Install MongoDB Enterprise on Ubuntu (page 27) Install the MongoDB Enterprise build and required depen-dencies
on Ubuntu Linux Systems using packages.
Install MongoDB Enterprise on Debian (page 30) Install the MongoDB Enterprise build and required depen-dencies
on Debian Linux Systems using packages.
Install MongoDB Enterprise on SUSE (page 32) Install the MongoDB Enterprise build and required depen-dencies
on SUSE Enterprise Linux.
Install MongoDB Enterprise on Amazon AMI (page 34) Install the MongoDB Enterprise build and required
dependencies on Amazon Linux AMI.
Install MongoDB Enterprise on Windows (page 36) Install the MongoDB Enterprise build and required de-pendencies
using the .msi installer.
5
10. MongoDB Documentation, Release 2.6.4
2.1.1 Install on Linux
These documents provide instructions to install MongoDB for various Linux systems.
Recommended
For easy installation, MongoDB provides packages for popular Linux distributions. The following guides detail the
installation process for these systems:
Install on Red Hat (page 6) Install MongoDB on Red Hat Enterprise, CentOS, Fedora and related Linux systems
using .rpm packages.
Install on Ubuntu (page 9) Install MongoDB on Ubuntu Linux systems using .deb packages.
Install on Debian (page 12) Install MongoDB on Debian systems using .deb packages.
For systems without supported packages, refer to the Manual Installation tutorial.
Manual Installation
Although packages are the preferred installation method, for Linux systems without supported packages, see the
following guide:
Install on Other Linux Systems (page 14) Install the official build of MongoDB on other Linux systems from Mon-goDB
archives.
Install MongoDB on Red Hat Enterprise, CentOS, Fedora, or Amazon Linux
Overview Use this tutorial to install MongoDB on Red Hat Enterprise Linux, CentOS Linux, Fedora Linux, or a
related system from .rpm packages. While some of these distributions include their own MongoDB packages, the
official MongoDB packages are generally more up to date.
Packages MongoDB provides packages of the officially supported MongoDB builds in it’s own repository. This
repository provides the MongoDB distribution in the following packages:
• mongodb-org
This package is a metapackage that will automatically install the four component packages listed below.
• mongodb-org-server
This package contains the mongod daemon and associated configuration and init scripts.
• mongodb-org-mongos
This package contains the mongos daemon.
• mongodb-org-shell
This package contains the mongo shell.
• mongodb-org-tools
This package contains the following MongoDB tools: mongoimport bsondump, mongodump,
mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,
mongostat, and mongotop.
6 Chapter 2. Install MongoDB
11. MongoDB Documentation, Release 2.6.4
Control Scripts The mongodb-org package includes various control scripts, including the init script
/etc/rc.d/init.d/mongod. These scripts are used to stop, start, and restart daemon processes.
The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. See
http://docs.mongodb.org/manualreference/configuration-options for documentation of the
configuration file.
As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).
You can use the mongod init script to derive your own mongos control script for use in such environments. See the
mongos reference for configuration details.
Warning: With the introduction of systemd in Fedora 15, the control scripts included in the packages available
in the MongoDB downloads repository are not compatible with Fedora systems. A correction is forthcoming; see
SERVER-7285a for more information. In the mean time use your own control scripts or install using the procedure
outlined in Install MongoDB on Linux Systems (page 14).
ahttps://jira.mongodb.org/browse/SERVER-7285
Considerations For production deployments, always run MongoDB on 64-bit systems.
The default /etc/mongodb.conf configuration file supplied by the 2.6 series packages has bind_ip‘ set to
127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.
Changed in version 2.6: The package structure and names have changed as of version 2.6. For instructions on instal-lation
of an older release, please refer to the documentation for the appropriate version.
Install MongoDB
Step 1: Configure the package management system (YUM). Create a /etc/yum.repos.d/mongodb.repo
file to hold the following configuration information for the MongoDB repository:
If you are running a 64-bit system, use the following configuration:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
If you are running a 32-bit system, which is not recommended for production deployments, use the following config-uration:
[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686/
gpgcheck=0
enabled=1
Step 2: Install the MongoDB packages and associated tools. When you install the packages, you choose whether
to install the current release or a previous one. This step provides the commands for both.
To install the latest stable version of MongoDB, issue the following command:
sudo yum install -y mongodb-org
2.1. Installation Guides 7
12. MongoDB Documentation, Release 2.6.4
To install a specific release of MongoDB, specify each component package individually and append the version number
to the package name, as in the following example that installs the 2.6.1‘ release of MongoDB:
sudo yum install -y mongodb-org-2.6.1 mongodb-org-server-2.6.1 mongodb-org-shell-2.6.1 mongodb-org-mongos-You can specify any available version of MongoDB. However yum will upgrade the packages when a newer version
becomes available. To prevent unintended upgrades, pin the package. To pin a package, add the following exclude
directive to your /etc/yum.conf file:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools
Previous versions of MongoDB packages use different naming conventions. See the 2.4 version of documentation for
more information1.
Run MongoDB
Important: You must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red Hat
Enterprise Linux, CentOS, Fedora). Administrators have three options:
• enable access to the relevant ports (e.g. 27017) for SELinux. See Default MongoDB Port (page 380) for more
information on MongoDB’s default ports. For default settings, this can be accomplished by running
semanage port -a -t mongodb_port_t -p tcp 27017
• set SELinux to permissive mode in /etc/selinux.conf. The line
SELINUX=enforcing
should be changed to
SELINUX=permissive
• disable SELinux entirely; as above but set
SELINUX=disabled
All three options require root privileges. The latter two options each requires a system reboot and may have larger
implications for your deployment.
You may alternatively choose not to install the SELinux packages when you are installing your Linux operating system,
or choose to remove the relevant packages. This option is the most invasive and is not recommended.
The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodb
by default, and runs using the mongod user account. You can specify alternate log and data file directories in
/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongo and /var/log/mongodb directories to give this users access to these directories.
Step 1: Start MongoDB. You can start the mongod process by issuing the following command:
sudo service mongod start
Step 2: Verify that MongoDB has started successfully You can verify that the mongod process has started suc-cessfully
by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
1http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-linux
8 Chapter 2. Install MongoDB
13. MongoDB Documentation, Release 2.6.4
[initandlisten] waiting for connections on port <port>
where <port> is the port configured in /etc/mongod.conf, 27017 by default.
You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:
sudo chkconfig mongod on
Step 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Step 4: Restart MongoDB. You can restart the mongod process by issuing the following command:
sudo service mongod restart
You can follow the state of the process for errors or important messages by watching the output in the
/var/log/mongodb/mongod.log file.
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
Install MongoDB on Ubuntu
Overview Use this tutorial to install MongoDB on Ubuntu Linux systems from .deb packages. While Ubuntu
includes its own MongoDB packages, the official MongoDB packages are generally more up-to-date.
Note: If you use an older Ubuntu that does not use Upstart (i.e. any version before 9.10 “Karmic”), please follow the
instructions on the Install MongoDB on Debian (page 12) tutorial.
Packages MongoDB provides packages of the officially supported MongoDB builds in it’s own repository. This
repository provides the MongoDB distribution in the following packages:
• mongodb-org
This package is a metapackage that will automatically install the four component packages listed below.
• mongodb-org-server
This package contains the mongod daemon and associated configuration and init scripts.
• mongodb-org-mongos
This package contains the mongos daemon.
• mongodb-org-shell
This package contains the mongo shell.
• mongodb-org-tools
This package contains the following MongoDB tools: mongoimport bsondump, mongodump,
mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,
mongostat, and mongotop.
2.1. Installation Guides 9
14. MongoDB Documentation, Release 2.6.4
Control Scripts The mongodb-org package includes various control scripts, including the init script
/etc/init.d/mongod. These scripts are used to stop, start, and restart daemon processes.
The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. See
http://docs.mongodb.org/manualreference/configuration-options for documentation of the
configuration file.
As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).
You can use the mongod init script to derive your own mongos control script for use in such environments. See the
mongos reference for configuration details.
Considerations For production deployments, always run MongoDB on 64-bit systems.
You cannot install this package concurrently with the mongodb, mongodb-server, or mongodb-clients pack-ages
provided by Ubuntu.
The default /etc/mongodb.conf configuration file supplied by the 2.6 series packages has bind_ip‘ set to
127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.
Changed in version 2.6: The package structure and names have changed as of version 2.6. For instructions on instal-lation
of an older release, please refer to the documentation for the appropriate version.
Install MongoDB
Step 1: Import the public key used by the package management system. The Ubuntu package management tools
(i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with
GPG keys. Issue the following command to import the MongoDB public GPG Key2:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Step 2: Create a list file for MongoDB. Create the /etc/apt/sources.list.d/mongodb.list list file
using the following command:
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.Step 3: Reload local package database. Issue the following command to reload the local package database:
sudo apt-get update
Step 4: Install the MongoDB packages. You can install either the latest stable version of MongoDB or a specific
version of MongoDB.
Install the latest stable version of MongoDB. Issue the following command:
sudo apt-get install -y mongodb-org
Install a specific release of MongoDB. Specify each component package individually and append the version num-ber
to the package name, as in the following example that installs the 2.6.1 release of MongoDB:
2http://docs.mongodb.org/10gen-gpg-key.asc
10 Chapter 2. Install MongoDB
15. MongoDB Documentation, Release 2.6.4
sudo apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-Pin a specific version of MongoDB. Although you can specify any available version of MongoDB, apt-get will
upgrade the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. To
pin the version of MongoDB at the currently installed version, issue the following command sequence:
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
Previous versions of MongoDB packages use different naming conventions. See the 2.4 version of documentation for
more information3.
Run MongoDB The MongoDB instance stores its data files in /var/lib/mongodb and its log files in
/var/log/mongodb by default, and runs using the mongodb user account. You can specify alternate log and
data file directories in /etc/mongodb.conf. See systemLog.path and storage.dbPath for additional
information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongodb and /var/log/mongodb directories to give this users access to these directories.
Step 1: Start MongoDB. Issue the following command to start mongod:
sudo service mongod start
Step 2: Verify that MongoDB has started successfully Verify that the mongod process has started successfully
by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
[initandlisten] waiting for connections on port <port>
where <port> is the port configured in /etc/mongod.conf, 27017 by default.
Step 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Step 4: Restart MongoDB. Issue the following command to restart mongod:
sudo service mongod restart
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
3http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-ubuntu
2.1. Installation Guides 11
16. MongoDB Documentation, Release 2.6.4
Install MongoDB on Debian
Overview Use this tutorial to install MongoDB on Debian systems from .deb packages. While some Debian
distributions include their own MongoDB packages, the official MongoDB packages are generally more up to date.
Note: This tutorial applies to both Debian systems and versions of Ubuntu Linux prior to 9.10 “Karmic” which do
not use Upstart. Other Ubuntu users will want to follow the Install MongoDB on Ubuntu (page 9) tutorial.
Packages MongoDB provides packages of the officially supported MongoDB builds in it’s own repository. This
repository provides the MongoDB distribution in the following packages:
• mongodb-org
This package is a metapackage that will automatically install the four component packages listed below.
• mongodb-org-server
This package contains the mongod daemon and associated configuration and init scripts.
• mongodb-org-mongos
This package contains the mongos daemon.
• mongodb-org-shell
This package contains the mongo shell.
• mongodb-org-tools
This package contains the following MongoDB tools: mongoimport bsondump, mongodump,
mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,
mongostat, and mongotop.
Control Scripts The mongodb-org package includes various control scripts, including the init script
/etc/init.d/mongod. These scripts are used to stop, start, and restart daemon processes.
The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. See
http://docs.mongodb.org/manualreference/configuration-options for documentation of the
configuration file.
As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).
You can use the mongod init script to derive your own mongos control script for use in such environments. See the
mongos reference for configuration details.
Considerations For production deployments, always run MongoDB on 64-bit systems.
You cannot install this package concurrently with the mongodb, mongodb-server, or mongodb-clients pack-ages
that your release of Debian may include.
The default /etc/mongodb.conf configuration file supplied by the 2.6 series packages has bind_ip‘ set to
127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.
Changed in version 2.6: The package structure and names have changed as of version 2.6. For instructions on instal-lation
of an older release, please refer to the documentation for the appropriate version.
Install MongoDB The Debian package management tools (i.e. dpkg and apt) ensure package consistency and
authenticity by requiring that distributors sign packages with GPG keys.
12 Chapter 2. Install MongoDB
17. MongoDB Documentation, Release 2.6.4
Step 1: Import the public key used by the package management system. Issue the following command to add
the MongoDB public GPG Key4 to the system key ring.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Step 2: Create a /etc/apt/sources.list.d/mongodb.list file for MongoDB. Create the list file using
the following command:
echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.Step 3: Reload local package database. Issue the following command to reload the local package database:
sudo apt-get update
Step 4: Install the MongoDB packages. You can install either the latest stable version of MongoDB or a specific
version of MongoDB.
Install the latest stable version of MongoDB. Issue the following command:
sudo apt-get install -y mongodb-org
Install a specific release of MongoDB. Specify each component package individually and append the version num-ber
to the package name, as in the following example that installs the 2.6.1 release of MongoDB:
sudo apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-Pin a specific version of MongoDB. Although you can specify any available version of MongoDB, apt-get will
upgrade the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. To
pin the version of MongoDB at the currently installed version, issue the following command sequence:
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
Previous versions of MongoDB packages use different naming conventions. See the 2.4 version of documentation for
more information5.
Run MongoDB The MongoDB instance stores its data files in /var/lib/mongodb and its log files in
/var/log/mongodb by default, and runs using the mongodb user account. You can specify alternate log and
data file directories in /etc/mongodb.conf. See systemLog.path and storage.dbPath for additional
information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongodb and /var/log/mongodb directories to give this users access to these directories.
4http://docs.mongodb.org/10gen-gpg-key.asc
5http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-ubuntu
2.1. Installation Guides 13
18. MongoDB Documentation, Release 2.6.4
Step 1: Start MongoDB. Issue the following command to start mongod:
sudo service mongod start
Step 2: Verify that MongoDB has started successfully Verify that the mongod process has started successfully
by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
[initandlisten] waiting for connections on port <port>
where <port> is the port configured in /etc/mongod.conf, 27017 by default.
Step 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Step 4: Restart MongoDB. Issue the following command to restart mongod:
sudo service mongod restart
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
Install MongoDB on Linux Systems
Overview Compiled versions of MongoDB for Linux provide a simple option for installing MongoDB for other
Linux systems without supported packages.
Considerations For production deployments, always run MongoDB on 64-bit systems.
Install MongoDB MongoDB provides archives for both 64-bit and 32-bit Linux. Follow the installation procedure
appropriate for your system.
Install for 64-bit Linux
Step 1: Download the binary files for the desired release of MongoDB. Download the binaries from
https://www.mongodb.org/downloads.
For example, to download the latest release through the shell, issue the following:
curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.4.tgz
Step 2: Extract the files from the downloaded archive. For example, from a system shell, you can extract through
the tar command:
tar -zxvf mongodb-linux-x86_64-2.6.4.tgz
14 Chapter 2. Install MongoDB
19. MongoDB Documentation, Release 2.6.4
Step 3: Copy the extracted archive to the target directory. Copy the extracted folder to the location from which
MongoDB will run.
mkdir -p mongodb
cp -R -n mongodb-linux-x86_64-2.6.4/ mongodb
Step 4: Ensure the location of the binaries is in the PATH variable. The MongoDB binaries are in the bin/
directory of the archive. To ensure that the binaries are in your PATH, you can modify your PATH.
For example, you can add the following line to your shell’s rc file (e.g. ~/.bashrc):
export PATH=<mongodb-install-directory>/bin:$PATH
Replace <mongodb-install-directory> with the path to the extracted MongoDB archive.
Install for 32-bit Linux
Step 1: Download the binary files for the desired release of MongoDB. Download the binaries from
https://www.mongodb.org/downloads.
For example, to download the latest release through the shell, issue the following:
curl -O http://downloads.mongodb.org/linux/mongodb-linux-i686-2.6.4.tgz
Step 2: Extract the files from the downloaded archive. For example, from a system shell, you can extract through
the tar command:
tar -zxvf mongodb-linux-i686-2.6.4.tgz
Step 3: Copy the extracted archive to the target directory. Copy the extracted folder to the location from which
MongoDB will run.
mkdir -p mongodb
cp -R -n mongodb-linux-i686-2.6.4/ mongodb
Step 4: Ensure the location of the binaries is in the PATH variable. The MongoDB binaries are in the bin/
directory of the archive. To ensure that the binaries are in your PATH, you can modify your PATH.
For example, you can add the following line to your shell’s rc file (e.g. ~/.bashrc):
export PATH=<mongodb-install-directory>/bin:$PATH
Replace <mongodb-install-directory> with the path to the extracted MongoDB archive.
Run MongoDB
Step 1: Create the data directory. Before you start MongoDB for the first time, create the directory to which
the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a
directory other than this one, you must specify that directory in the dbpath option when starting the mongod process
later in this procedure.
The following example command creates the default /data/db directory:
2.1. Installation Guides 15
20. MongoDB Documentation, Release 2.6.4
mkdir -p /data/db
Step 2: Set permissions for the data directory. Before running mongod for the first time, ensure that the user
account running mongod has read and write permissions for the directory.
Step 3: Run MongoDB. To run MongoDB, run the mongod process at the system prompt. If necessary, specify the
path of the mongod or the data directory. See the following examples.
Run without specifying paths If your system PATH variable includes the location of the mongod binary and if you
use the default data directory (i.e., /data/db), simply enter mongod at the system prompt:
mongod
Specify the path of the mongod If your PATH does not include the location of the mongod binary, enter the full
path to the mongod binary at the system prompt:
<path to binary>/mongod
Specify the path of the data directory If you do not use the default data directory (i.e., /data/db), specify the
path to the data directory using the --dbpath option:
mongod --dbpath <path to data directory>
Step 4: Stop MongoDB as needed. To stop MongoDB, press Control+C in the terminal where the mongod
instance is running.
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
2.1.2 Install MongoDB on OS X
Overview
Use this tutorial to install MongoDB on on OS X systems.
Platform Support
Starting in version 2.4, MongoDB only supports OS X versions 10.6 (Snow Leopard) on Intel x86-64 and later.
MongoDB is available through the popular OS X package manager Homebrew6 or through the MongoDB Download
site7.
Install MongoDB
You can install MongoDB with Homebrew8 or manually. This section describes both.
6http://brew.sh/
7http://www.mongodb.org/downloads
8http://brew.sh/
16 Chapter 2. Install MongoDB
21. MongoDB Documentation, Release 2.6.4
Install MongoDB with Homebrew
Homebrew9 installs binary packages based on published “formulae.” This section describes how to update brew to
the latest packages and install MongoDB. Homebrew requires some initial setup and configuration, which is beyond
the scope of this document.
Step 1: Update Homebrew’s package database.
In a system shell, issue the following command:
brew update
Step 2: Install MongoDB.
You can install MongoDB with via brew with several different options. Use one of the following operations:
Install the MongoDB Binaries To install the MongoDB binaries, issue the following command in a system shell:
brew install mongodb
Build MongoDB from Source with SSL Support To build MongoDB from the source files and include SSL sup-port,
issue the following from a system shell:
brew install mongodb --with-openssl
Install the Latest Development Release of MongoDB To install the latest development release for use in testing
and development, issue the following command in a system shell:
brew install mongodb --devel
Install MongoDB Manually
Only install MongoDB using this procedure if you cannot use homebrew (page 17).
Step 1: Download the binary files for the desired release of MongoDB.
Download the binaries from https://www.mongodb.org/downloads.
For example, to download the latest release through the shell, issue the following:
curl -O http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.4.tgz
Step 2: Extract the files from the downloaded archive.
For example, from a system shell, you can extract through the tar command:
9http://brew.sh/
2.1. Installation Guides 17
22. MongoDB Documentation, Release 2.6.4
tar -zxvf mongodb-osx-x86_64-2.6.4.tgz
Step 3: Copy the extracted archive to the target directory.
Copy the extracted folder to the location from which MongoDB will run.
mkdir -p mongodb
cp -R -n mongodb-osx-x86_64-2.6.4/ mongodb
Step 4: Ensure the location of the binaries is in the PATH variable.
The MongoDB binaries are in the bin/ directory of the archive. To ensure that the binaries are in your PATH, you
can modify your PATH.
For example, you can add the following line to your shell’s rc file (e.g. ~/.bashrc):
export PATH=<mongodb-install-directory>/bin:$PATH
Replace <mongodb-install-directory> with the path to the extracted MongoDB archive.
Run MongoDB
Step 1: Create the data directory.
Before you start MongoDB for the first time, create the directory to which the mongod process will write data. By
default, the mongod process uses the /data/db directory. If you create a directory other than this one, you must
specify that directory in the dbpath option when starting the mongod process later in this procedure.
The following example command creates the default /data/db directory:
mkdir -p /data/db
Step 2: Set permissions for the data directory.
Before running mongod for the first time, ensure that the user account running mongod has read and write permis-sions
for the directory.
Step 3: Run MongoDB.
To run MongoDB, run the mongod process at the system prompt. If necessary, specify the path of the mongod or the
data directory. See the following examples.
Run without specifying paths If your system PATH variable includes the location of the mongod binary and if you
use the default data directory (i.e., /data/db), simply enter mongod at the system prompt:
mongod
18 Chapter 2. Install MongoDB
23. MongoDB Documentation, Release 2.6.4
Specify the path of the mongod If your PATH does not include the location of the mongod binary, enter the full
path to the mongod binary at the system prompt:
<path to binary>/mongod
Specify the path of the data directory If you do not use the default data directory (i.e., /data/db), specify the
path to the data directory using the --dbpath option:
mongod --dbpath <path to data directory>
Step 4: Stop MongoDB as needed.
To stop MongoDB, press Control+C in the terminal where the mongod instance is running.
Step 5: Begin using MongoDB.
To begin using MongoDB, see Getting Started with MongoDB (page 43). Also consider the Production Notes
(page 188) document before deploying MongoDB in a production environment.
2.1.3 Install MongoDB on Windows
Overview
Use this tutorial to install MongoDB on a Windows systems.
Platform Support
Starting in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to use
more recent releases of MongoDB.
Important: If you are running any edition of Windows Server 2008 R2 or Windows 7, please install a hotfix to
resolve an issue with memory mapped files on Windows10.
Install MongoDB
Step 1: Determine which MongoDB build you need.
There are three builds of MongoDB for Windows:
MongoDB for Windows Server 2008 R2 edition (i.e. 2008R2) runs only on Windows Server 2008 R2, Windows 7
64-bit, and newer versions of Windows. This build takes advantage of recent enhancements to the Windows Platform
and cannot operate on older versions of Windows.
MongoDB forWindows 64-bit runs on any 64-bit version of Windows newer than Windows XP, including Windows
Server 2008 R2 and Windows 7 64-bit.
MongoDB for Windows 32-bit runs on any 32-bit version of Windows newer than Windows XP. 32-bit versions of
MongoDB are only intended for older systems and for use in testing and development systems. 32-bit versions of
MongoDB only support databases smaller than 2GB.
10http://support.microsoft.com/kb/2731284
2.1. Installation Guides 19
24. MongoDB Documentation, Release 2.6.4
To find which version of Windows you are running, enter the following command in the Command Prompt:
wmic os get osarchitecture
Step 2: Download MongoDB for Windows.
Download the latest production release of MongoDB from the MongoDB downloads page11. Ensure you download
the correct version of MongoDB for your Windows system. The 64-bit versions of MongoDB does not work with
32-bit Windows.
Step 3: Install the downloaded file.
InWindows Explorer, locate the downloaded MongoDB msi file, which typically is located in the default Downloads
folder. Double-click the msi file. A set of screens will appear to guide you through the installation process.
Step 4: Move the MongoDB folder to another location (optional).
To move the MongoDB folder, you must issue the move command as an Administrator. For example, to move the
folder to C:mongodb:
Select Start Menu > All Programs > Accessories.
Right-click Command Prompt and select Run as Administrator from the popup menu.
Issue the following commands:
cd
move C:mongodb-win32-* C:mongodb
MongoDB is self-contained and does not have any other system dependencies. You can run MongoDB from any folder
you choose. You may install MongoDB in any folder (e.g. D:testmongodb)
Run MongoDB
Warning: Do not make mongod.exe visible on public networks without running in “Secure Mode” with the
auth setting. MongoDB is designed to be run in trusted environments, and the database does not enable “Secure
Mode” by default.
Step 1: Set up the MongoDB environment.
MongoDB requires a data directory to store all data. MongoDB’s default data directory path is datadb. Create
this folder using the following commands from a Command Prompt:
md datadb
You can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:
C:mongodbbinmongod.exe --dbpath d:testmongodbdata
If your path includes spaces, enclose the entire path in double quotes, for example:
11http://www.mongodb.org/downloads
20 Chapter 2. Install MongoDB
25. MongoDB Documentation, Release 2.6.4
C:mongodbbinmongod.exe --dbpath "d:testmongo db data"
Step 2: Start MongoDB.
To start MongoDB, run mongod.exe. For example, from the Command Prompt:
C:Program FilesMongoDBbinmongod.exe
This starts the main MongoDB database process. The waiting for connections message in the console
output indicates that the mongod.exe process is running successfully.
Depending on the security level of your system, Windows may pop up a Security Alert dialog box about block-ing
“some features” of C:Program FilesMongoDBbinmongod.exe from communicating on networks.
All users should select Private Networks, such as my home or work network and click Allow
access. For additional information on security and MongoDB, please see the Security Documentation (page 281).
Step 3: Connect to MongoDB.
To connect to MongoDB through the mongo.exe shell, open another Command Prompt. When connecting, specify
the data directory if necessary. This step provides several example connection commands.
If your MongoDB installation uses the default data directory, connect without specifying the data directory:
C:mongodbbinmongo.exe
If you installation uses a different data directory, specify the directory when connecting, as in this example:
C:mongodbbinmongod.exe --dbpath d:testmongodbdata
If your path includes spaces, enclose the entire path in double quotes. For example:
C:mongodbbinmongod.exe --dbpath "d:testmongo db data"
If you want to develop applications using .NET, see the documentation of C# and MongoDB12 for more information.
Step 4: Begin using MongoDB.
To begin using MongoDB, see Getting Started with MongoDB (page 43). Also consider the Production Notes
(page 188) document before deploying MongoDB in a production environment.
Configure a Windows Service for MongoDB
Note: There is a known issue for MongoDB 2.6.0, SERVER-1351513, which prevents the use of the instructions
in this section. For MongoDB 2.6.0, use Manually Create a Windows Service for MongoDB (page 22) to create a
Windows Service for MongoDB instead.
12http://docs.mongodb.org/ecosystem/drivers/csharp
13https://jira.mongodb.org/browse/SERVER-13515
2.1. Installation Guides 21
26. MongoDB Documentation, Release 2.6.4
Step 1: Configure directories and files.
Create a configuration file and a directory path for MongoDB log output (logpath):
Create a specific directory for MongoDB log files:
md "C:Program FilesMongoDBlog"
In the Command Prompt, create a configuration file for the logpath option for MongoDB:
echo logpath="C:Program FilesMongoDBlogmongo.log" > "C:Program FilesMongoDBmongod.cfg"
Step 2: Run the MongoDB service.
Run all of the following commands in Command Prompt with “Administrative Privileges:”
Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option.
"C:Program FilesMongoDBbinmongod.exe" --config "C:Program FilesMongoDBmongod.cfg" --install
Modify the path to the mongod.cfg file as needed.
To use an alternate dbpath, specify the path in the configuration file (e.g. C:Program
FilesMongoDBmongod.cfg) or on the command line with the --dbpath option.
If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is datadb.
If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service with
a unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient system
resources exist and your system design requires it.
Step 3: Stop or remove the MongoDB service as needed.
To stop the MongoDB service use the following command:
net stop MongoDB
To remove the MongoDB service use the following command:
"C:Program FilesMongoDBbinmongod.exe" --remove
Manually Create a Windows Service for MongoDB
The following procedure assumes you have installed MongoDB using the MSI installer, with the default path
C:Program FilesMongoDB 2.6 Standard.
If you have installed in an alternative directory, you will need to adjust the paths as appropriate.
Step 1: Open an Administrator command prompt.
Windows 7 / Vista / Server 2008 (and R2) Press Win + R, then type cmd, then press Ctrl + Shift +
Enter.
22 Chapter 2. Install MongoDB
27. MongoDB Documentation, Release 2.6.4
Windows 8 Press Win + X, then press A.
Execute the remaining steps from the Administrator command prompt.
Step 2: Create directories.
Create directories for your database and log files:
mkdir c:datadb
mkdir c:datalog
Step 3: Create a configuration file.
Create a configuration file. This file can include any of the configuration options for mongod, but
must include a valid setting for logpath:
The following creates a configuration file, specifying both the logpath and the dbpath settings in the configuration
file:
echo logpath=c:datalogmongod.log> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"
echo dbpath=c:datadb>> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"
Step 4: Create the MongoDB service.
Create the MongoDB service.
sc.exe create MongoDB binPath= ""C:Program FilesMongoDB 2.6 Standardbinmongod.exe" --service --sc.exe requires a space between “=” and the configuration values (eg “binPath= ”), and a “” to escape double quotes.
If successfully created, the following log message will display:
[SC] CreateService SUCCESS
Step 5: Start the MongoDB service.
net start MongoDB
Step 6: Stop or remove the MongoDB service as needed.
To stop the MongoDB service, use the following command:
net stop MongoDB
To remove the MongoDB service, first stop the service and then run the following command:
sc.exe delete MongoDB
2.1. Installation Guides 23
28. MongoDB Documentation, Release 2.6.4
2.1.4 Install MongoDB Enterprise
These documents provide instructions to install MongoDB Enterprise for Linux and Windows Systems.
Install MongoDB Enterprise on Red Hat (page 24) Install the MongoDB Enterprise build and required dependen-cies
on Red Hat Enterprise or CentOS Systems using packages.
Install MongoDB Enterprise on Ubuntu (page 27) Install the MongoDB Enterprise build and required dependencies
on Ubuntu Linux Systems using packages.
Install MongoDB Enterprise on Debian (page 30) Install the MongoDB Enterprise build and required dependencies
on Debian Linux Systems using packages.
Install MongoDB Enterprise on SUSE (page 32) Install the MongoDB Enterprise build and required dependencies
on SUSE Enterprise Linux.
Install MongoDB Enterprise on Amazon AMI (page 34) Install the MongoDB Enterprise build and required depen-dencies
on Amazon Linux AMI.
Install MongoDB Enterprise on Windows (page 36) Install the MongoDB Enterprise build and required dependen-cies
using the .msi installer.
Install MongoDB Enterprise on Red Hat Enterprise or CentOS
Overview
Use this tutorial to install MongoDB Enterprise on Red Hat Enterprise Linux or CentOS Linux from .rpm packages.
Packages
MongoDB provides packages of the officially supported MongoDB Enterprise builds in it’s own repository. This
repository provides the MongoDB Enterprise distribution in the following packages:
• mongodb-enterprise
This package is a metapackage that will automatically install the four component packages listed below.
• mongodb-enterprise-server
This package contains the mongod daemon and associated configuration and init scripts.
• mongodb-enterprise-mongos
This package contains the mongos daemon.
• mongodb-enterprise-shell
This package contains the mongo shell.
• mongodb-enterprise-tools
This package contains the following MongoDB tools: mongoimport bsondump, mongodump,
mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,
mongostat, and mongotop.
24 Chapter 2. Install MongoDB
29. MongoDB Documentation, Release 2.6.4
Control Scripts
The mongodb-enterprise package includes various control scripts, including the init script
/etc/rc.d/init.d/mongod.
The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts.
As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).
You can use the mongod init script to derive your own mongos control script.
Considerations
MongoDB only provides Enterprise packages for Red Hat Enterprise Linux and CentOS Linux versions 5 and 6,
64-bit.
The default /etc/mongodb.conf configuration file supplied by the 2.6 series packages has bind_ip‘ set to
127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.
Changed in version 2.6: The package structure and names have changed as of version 2.6. For instructions on instal-lation
of an older release, please refer to the documentation for the appropriate version.
Install MongoDB Enterprise
When you install the packages for MongoDB Enterprise, you choose whether to install the current release or a previous
one. This procedure describes how to do both.
Step 1: Configure repository. Create an /etc/yum.repos.d/mongodb-enterprise.repo file so that
you can install MongoDB enterprise directly, using yum.
Use the following repository file to specify the latest stable release of MongoDB enterprise.
[mongodb-enterprise]
name=MongoDB Enterprise Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/
gpgcheck=0
enabled=1
Use the following repository to install only versions of MongoDB for the 2.6 release. If you’d like to install Mon-goDB
Enterprise packages from a particular release series (page 808), such as 2.4 or 2.6, you can specify the re-lease
series in the repository configuration. For example, to restrict your system to the 2.6 release series, create a
/etc/yum.repos.d/mongodb-enterprise-2.6.repo file to hold the following configuration information
for the MongoDB Enterprise 2.6 repository:
[mongodb-enterprise-2.6]
name=MongoDB Enterprise 2.6 Repository
baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/2.6/$basearch/
gpgcheck=0
enabled=1
.repo files for each release can also be found in the repository itself14. Remember that odd-numbered minor release
versions (e.g. 2.5) are development versions and are unsuitable for production deployment.
Step 1: Install the MongoDB Enterprise packages and associated tools. You can install either the latest stable
version of MongoDB Enterprise or a specific version of MongoDB Enterprise.
14https://repo.mongodb.com/yum/redhat/
2.1. Installation Guides 25
30. MongoDB Documentation, Release 2.6.4
Install the latest stable version of MongoDB Enterprise. Issue the following command:
sudo yum install -y mongodb-enterprise
Step 2: Optional. Manage Installed Version
Install a specific release of MongoDB Enterprise. Specify each component package individually and append the
version number to the package name, as in the following example that installs the 2.6.1 release of MongoDB:
sudo yum install -y mongodb-enterprise-2.6.1 mongodb-enterprise-server-2.6.1 mongodb-enterprise-shell-Pin a specific version of MongoDB Enterprise. Although you can specify any available version of MongoDB
Enterprise, yum will upgrade the packages when a newer version becomes available. To prevent unintended upgrades,
pin the package. To pin a package, add the following exclude directive to your /etc/yum.conf file:
exclude=mongodb-enterprise,mongodb-enterprise-server,mongodb-enterprise-shell,mongodb-enterprise-mongos,Previous versions of MongoDB packages use different naming conventions. See the 2.4 version of documentation for
more information15.
Step 3: When the install completes, you can run MongoDB.
Run MongoDB Enterprise
Important: You must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red Hat
Enterprise Linux, CentOS, Fedora). Administrators have three options:
• enable access to the relevant ports (e.g. 27017) for SELinux. See Default MongoDB Port (page 380) for more
information on MongoDB’s default ports. For default settings, this can be accomplished by running
semanage port -a -t mongodb_port_t -p tcp 27017
• set SELinux to permissive mode in /etc/selinux.conf. The line
SELINUX=enforcing
should be changed to
SELINUX=permissive
• disable SELinux entirely; as above but set
SELINUX=disabled
All three options require root privileges. The latter two options each requires a system reboot and may have larger
implications for your deployment.
You may alternatively choose not to install the SELinux packages when you are installing your Linux operating system,
or choose to remove the relevant packages. This option is the most invasive and is not recommended.
The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodb
by default, and runs using the mongod user account. You can specify alternate log and data file directories in
/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.
15http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-linux
26 Chapter 2. Install MongoDB
31. MongoDB Documentation, Release 2.6.4
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongo and /var/log/mongodb directories to give this users access to these directories.
Step 1: Start MongoDB. You can start the mongod process by issuing the following command:
sudo service mongod start
Step 2: Verify that MongoDB has started successfully You can verify that the mongod process has started suc-cessfully
by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
[initandlisten] waiting for connections on port <port>
where <port> is the port configured in /etc/mongod.conf, 27017 by default.
You can optionally ensure that MongoDB will start following a system reboot by issuing the following command:
sudo chkconfig mongod on
Step 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Step 4: Restart MongoDB. You can restart the mongod process by issuing the following command:
sudo service mongod restart
You can follow the state of the process for errors or important messages by watching the output in the
/var/log/mongodb/mongod.log file.
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
Install MongoDB Enterprise on Ubuntu
Overview
Use this tutorial to install MongoDB Enterprise on Ubuntu Linux systems from .deb packages.
Packages
MongoDB provides packages of the officially supported MongoDB Enterprise builds in it’s own repository. This
repository provides the MongoDB Enterprise distribution in the following packages:
• mongodb-enterprise
This package is a metapackage that will automatically install the four component packages listed below.
• mongodb-enterprise-server
This package contains the mongod daemon and associated configuration and init scripts.
• mongodb-enterprise-mongos
This package contains the mongos daemon.
2.1. Installation Guides 27
32. MongoDB Documentation, Release 2.6.4
• mongodb-enterprise-shell
This package contains the mongo shell.
• mongodb-enterprise-tools
This package contains the following MongoDB tools: mongoimport bsondump, mongodump,
mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,
mongostat, and mongotop.
Control Scripts
The mongodb-enterprise package includes various control scripts, including the init script
/etc/rc.d/init.d/mongod.
The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts.
As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).
You can use the mongod init script to derive your own mongos control script.
Considerations
MongoDB only provides Enterprise packages for Ubuntu 12.04 LTS (Precise Pangolin).
Changed in version 2.6: The package structure and names have changed as of version 2.6. For instructions on instal-lation
of an older release, please refer to the documentation for the appropriate version.
Install MongoDB Enterprise
Step 1: Import the public key used by the package management system. The Ubuntu package management tools
(i.e. dpkg and apt) ensure package consistency and authenticity by requiring that distributors sign packages with
GPG keys. Issue the following command to import the MongoDB public GPG Key16:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
Step 2: Create a /etc/apt/sources.list.d/mongodb-enterprise.list file for MongoDB. Create
the list file using the following command:
echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/stable multiverse' | sudo tee If you’d like to install MongoDB Enterprise packages from a particular release series (page 808), such as 2.4 or 2.6,
you can specify the release series in the repository configuration. For example, to restrict your system to the 2.6 release
series, add the following repository:
echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/2.6 multiverse' | sudo tee /etc/Step 3: Reload local package database. Issue the following command to reload the local package database:
sudo apt-get update
16http://docs.mongodb.org/10gen-gpg-key.asc
28 Chapter 2. Install MongoDB
33. MongoDB Documentation, Release 2.6.4
Step 4: Install the MongoDB Enterprise packages. When you install the packages, you choose whether to install
the current release or a previous one. This step provides instructions for both.
To install the latest stable version of MongoDB Enterprise, issue the following command:
sudo apt-get install mongodb-enterprise
To install a specific release of MongoDB Enterprise, specify each component package individually and append the
version number to the package name, as in the following example that installs the 2.6.1‘ release of MongoDB Enter-prise:
apt-get install mongodb-enterprise=2.6.1 mongodb-enterprise-server=2.6.1 mongodb-enterprise-shell=2.6.1 You can specify any available version of MongoDB Enterprise. However apt-get will upgrade the packages when
a newer version becomes available. To prevent unintended upgrades, pin the package. To pin the version of MongoDB
Enterprise at the currently installed version, issue the following command sequence:
echo "mongodb-enterprise hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-server hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-shell hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-mongos hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-tools hold" | sudo dpkg --set-selections
Previous versions of MongoDB Enterprise packages use different naming conventions. See the 2.4 version of docu-mentation17
for more information.
Run MongoDB Enterprise
The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb
by default, and runs using the mongodb user account. You can specify alternate log and data file directories in
/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongodb and /var/log/mongodb directories to give this users access to these directories.
Step 1: Start MongoDB. Issue the following command to start mongod:
sudo service mongod start
Step 2: Verify that MongoDB has started successfully Verify that the mongod process has started successfully
by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
[initandlisten] waiting for connections on port <port>
where <port> is the port configured in /etc/mongod.conf, 27017 by default.
Step 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Step 4: Restart MongoDB. Issue the following command to restart mongod:
17http://docs.mongodb.org/v2.4/tutorial/install-mongodb-enterprise
2.1. Installation Guides 29
34. MongoDB Documentation, Release 2.6.4
sudo service mongod restart
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
Install MongoDB Enterprise on Debian
Overview
Use this tutorial to install MongoDB Enterprise on Debian Linux systems from .deb packages.
Packages
MongoDB provides packages of the officially supported MongoDB Enterprise builds in it’s own repository. This
repository provides the MongoDB Enterprise distribution in the following packages:
• mongodb-enterprise
This package is a metapackage that will automatically install the four component packages listed below.
• mongodb-enterprise-server
This package contains the mongod daemon and associated configuration and init scripts.
• mongodb-enterprise-mongos
This package contains the mongos daemon.
• mongodb-enterprise-shell
This package contains the mongo shell.
• mongodb-enterprise-tools
This package contains the following MongoDB tools: mongoimport bsondump, mongodump,
mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,
mongostat, and mongotop.
Control Scripts
The mongodb-enterprise package includes various control scripts, including the init script
/etc/rc.d/init.d/mongod.
The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts.
As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).
You can use the mongod init script to derive your own mongos control script.
Considerations
Changed in version 2.6: The package structure and names have changed as of version 2.6. For instructions on instal-lation
of an older release, please refer to the documentation for the appropriate version.
MongoDB only provides Enterprise packages for 64-bit versions of Debian Wheezy.
30 Chapter 2. Install MongoDB
35. MongoDB Documentation, Release 2.6.4
Install MongoDB Enterprise
Step 1: Import the public key used by the package management system. Issue the following command to add
the MongoDB public GPG Key18 to the system key ring.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
Step 2: Create a /etc/apt/sources.list.d/mongodb-enterprise.list file for MongoDB. Create
the list file using the following command:
echo 'deb http://repo.mongodb.com/apt/debian wheezy/mongodb-enterprise/stable main' | sudo tee /etc/apt/If you’d like to install MongoDB Enterprise packages from a particular release series (page 808), such as 2.6, you can
specify the release series in the repository configuration. For example, to restrict your system to the 2.6 release series,
add the following repository:
echo 'deb http://repo.mongodb.com/apt/debian precise/mongodb-enterprise/2.6 main' | sudo tee /etc/apt/Step 3: Reload local package database. Issue the following command to reload the local package database:
sudo apt-get update
Step 4: Install the MongoDB Enterprise packages. When you install the packages, you choose whether to install
the current release or a previous one. This step provides instructions for both.
To install the latest stable version of MongoDB Enterprise, issue the following command:
sudo apt-get install mongodb-enterprise
To install a specific release of MongoDB Enterprise, specify each component package individually and append the
version number to the package name, as in the following example that installs the 2.6.1‘ release of MongoDB Enter-prise:
apt-get install mongodb-enterprise=2.6.1 mongodb-enterprise-server=2.6.1 mongodb-enterprise-shell=2.6.1 You can specify any available version of MongoDB Enterprise. However apt-get will upgrade the packages when
a newer version becomes available. To prevent unintended upgrades, pin the package. To pin the version of MongoDB
Enterprise at the currently installed version, issue the following command sequence:
echo "mongodb-enterprise hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-server hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-shell hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-mongos hold" | sudo dpkg --set-selections
echo "mongodb-enterprise-tools hold" | sudo dpkg --set-selections
Run MongoDB Enterprise
The MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodb
by default, and runs using the mongodb user account. You can specify alternate log and data file directories in
/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongodb and /var/log/mongodb directories to give this users access to these directories.
18http://docs.mongodb.org/10gen-gpg-key.asc
2.1. Installation Guides 31
36. MongoDB Documentation, Release 2.6.4
Step 1: Start MongoDB. Issue the following command to start mongod:
sudo service mongod start
Step 2: Verify that MongoDB has started successfully Verify that the mongod process has started successfully
by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading
[initandlisten] waiting for connections on port <port>
where <port> is the port configured in /etc/mongod.conf, 27017 by default.
Step 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:
sudo service mongod stop
Step 4: Restart MongoDB. Issue the following command to restart mongod:
sudo service mongod restart
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
Install MongoDB Enterprise on SUSE
Overview
Use this tutorial to install MongoDB Enterprise on SUSE Linux. MongoDB Enterprise is available on select platforms
and contains support for several features related to security and monitoring.
Prerequisites
To use MongoDB Enterprise on SUSE Enterprise Linux, you must install several prerequisite packages:
• libopenssl0_9_8
• libsnmp15
• net-snmp
• snmp-mibs
• cyrus-sasl
• cyrus-sasl-gssapi
To install these packages, you can issue the following command:
sudo zypper install libopenssl0_9_8 net-snmp libsnmp15 snmp-mibs cyrus-sasl cyrus-sasl-gssapi
32 Chapter 2. Install MongoDB
37. MongoDB Documentation, Release 2.6.4
Install MongoDB Enterprise
Note: The Enterprise packages include an example SNMP configuration file named mongod.conf. This file is not
a MongoDB configuration file.
Step 1: Download and install the MongoDB Enterprise packages. After you have in-stalled
the required prerequisite packages, download and install the MongoDB Enterprise packages
from http://www.mongodb.com/subscription/downloads. The MongoDB binaries are located in the
http://docs.mongodb.org/manualbin directory of the archive. To download and install, use the
following sequence of commands.
curl -O http://downloads.10gen.com/linux/mongodb-linux-x86_64-subscription-suse11-2.6.4.tgz
tar -zxvf mongodb-linux-x86_64-subscription-suse11-2.6.4.tgz
cp -R -n mongodb-linux-x86_64-subscription-suse11-2.6.4/ mongodb
Step 2: Ensure the location of the MongoDB binaries is included in the PATH variable. Once you have copied
the MongoDB binaries to their target location, ensure that the location is included in your PATH variable. If it is not,
either include it or create symbolic links from the binaries to a directory that is included.
Run MongoDB Enterprise
Step 1: Create the data directory. Before you start MongoDB for the first time, create the directory to which
the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a
directory other than this one, you must specify that directory in the dbpath option when starting the mongod process
later in this procedure.
The following example command creates the default /data/db directory:
mkdir -p /data/db
Step 2: Set permissions for the data directory. Before running mongod for the first time, ensure that the user
account running mongod has read and write permissions for the directory.
Step 3: Run MongoDB. To run MongoDB, run the mongod process at the system prompt. If necessary, specify the
path of the mongod or the data directory. See the following examples.
Run without specifying paths If your system PATH variable includes the location of the mongod binary and if you
use the default data directory (i.e., /data/db), simply enter mongod at the system prompt:
mongod
Specify the path of the mongod If your PATH does not include the location of the mongod binary, enter the full
path to the mongod binary at the system prompt:
<path to binary>/mongod
2.1. Installation Guides 33
38. MongoDB Documentation, Release 2.6.4
Specify the path of the data directory If you do not use the default data directory (i.e., /data/db), specify the
path to the data directory using the --dbpath option:
mongod --dbpath <path to data directory>
Step 4: Stop MongoDB as needed. To stop MongoDB, press Control+C in the terminal where the mongod
instance is running.
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
Install MongoDB Enterprise on Amazon Linux AMI
Overview
Use this tutorial to install MongoDB Enterprise on Amazon Linux AMI. MongoDB Enterprise is available on select
platforms and contains support for several features related to security and monitoring.
Prerequisites
To use MongoDB Enterprise on Amazon Linux AMI, you must install several prerequisite packages:
• net-snmp
• net-snmp-libs
• openssl
• net-snmp-utils
• cyrus-sasl
• cyrus-sasl-lib
• cyrus-sasl-devel
• cyrus-sasl-gssapi
To install these packages, you can issue the following command:
sudo yum install openssl net-snmp net-snmp-libs net-snmp-utils cyrus-sasl cyrus-sasl-lib cyrus-sasl-devel Install MongoDB Enterprise
Note: The Enterprise packages include an example SNMP configuration file named mongod.conf. This file is not
a MongoDB configuration file.
Step 1: Download and install the MongoDB Enterprise packages. After you have in-stalled
the required prerequisite packages, download and install the MongoDB Enterprise packages
from http://www.mongodb.com/subscription/downloads. The MongoDB binaries are located in the
http://docs.mongodb.org/manualbin directory of the archive. To download and install, use the
following sequence of commands.
34 Chapter 2. Install MongoDB
39. MongoDB Documentation, Release 2.6.4
curl -O http://downloads.10gen.com/linux/mongodb-linux-x86_64-subscription-amzn64-2.6.4.tgz
tar -zxvf mongodb-linux-x86_64-subscription-amzn64-2.6.4.tgz
cp -R -n mongodb-linux-x86_64-subscription-amzn64-2.6.4/ mongodb
Step 2: Ensure the location of the MongoDB binaries is included in the PATH variable. Once you have copied
the MongoDB binaries to their target location, ensure that the location is included in your PATH variable. If it is not,
either include it or create symbolic links from the binaries to a directory that is included.
Run MongoDB Enterprise
The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodb
by default, and runs using the mongod user account. You can specify alternate log and data file directories in
/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongo and /var/log/mongodb directories to give this users access to these directories.
Step 1: Create the data directory. Before you start MongoDB for the first time, create the directory to which
the mongod process will write data. By default, the mongod process uses the /data/db directory. If you create a
directory other than this one, you must specify that directory in the dbpath option when starting the mongod process
later in this procedure.
The following example command creates the default /data/db directory:
mkdir -p /data/db
Step 2: Set permissions for the data directory. Before running mongod for the first time, ensure that the user
account running mongod has read and write permissions for the directory.
Step 3: Run MongoDB. To run MongoDB, run the mongod process at the system prompt. If necessary, specify the
path of the mongod or the data directory. See the following examples.
Run without specifying paths If your system PATH variable includes the location of the mongod binary and if you
use the default data directory (i.e., /data/db), simply enter mongod at the system prompt:
mongod
Specify the path of the mongod If your PATH does not include the location of the mongod binary, enter the full
path to the mongod binary at the system prompt:
<path to binary>/mongod
Specify the path of the data directory If you do not use the default data directory (i.e., /data/db), specify the
path to the data directory using the --dbpath option:
mongod --dbpath <path to data directory>
Step 4: Stop MongoDB as needed. To stop MongoDB, press Control+C in the terminal where the mongod
instance is running.
2.1. Installation Guides 35
40. MongoDB Documentation, Release 2.6.4
Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
Install MongoDB Enterprise on Windows
New in version 2.6.
Overview
Use this tutorial to install MongoDB Enterprise on Windows systems. MongoDB Enterprise is available on select
platforms and contains support for several features related to security and monitoring.
Prerequisites
MongoDB Enterprise Server for Windows requires Windows Server 2008 R2 or later. The MSI installer includes all
other software dependencies.
Install MongoDB Enterprise
Step 1: Download MongoDB Enterprise for Windows. Download the latest production release of MongoDB
Enterprise19
Step 2: Install MongoDB Enterprise for Windows. Run the downloaded MSI installer. Make configuration
choices as prompted.
MongoDB is self-contained and does not have any other system dependencies. You can install MongoDB into any
folder (e.g. D:testmongodb) and run it from there. The installation wizard includes an option to select an
installation directory.
Run MongoDB Enterprise
Warning: Do not make mongod.exe visible on public networks without running in “Secure Mode” with the
auth setting. MongoDB is designed to be run in trusted environments, and the database does not enable “Secure
Mode” by default.
Step 1: Set up the MongoDB environment. MongoDB requires a data directory to store all data. MongoDB’s
default data directory path is datadb. Create this folder using the following commands from a Command Prompt:
md datadb
You can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:
C:mongodbbinmongod.exe --dbpath d:testmongodbdata
If your path includes spaces, enclose the entire path in double quotes, for example:
19http://www.mongodb.com/products/mongodb-enterprise
36 Chapter 2. Install MongoDB
41. MongoDB Documentation, Release 2.6.4
C:mongodbbinmongod.exe --dbpath "d:testmongo db data"
Step 2: Start MongoDB. To start MongoDB, run mongod.exe. For example, from the Command Prompt:
C:Program FilesMongoDBbinmongod.exe
This starts the main MongoDB database process. The waiting for connections message in the console
output indicates that the mongod.exe process is running successfully.
Depending on the security level of your system, Windows may pop up a Security Alert dialog box about block-ing
“some features” of C:Program FilesMongoDBbinmongod.exe from communicating on networks.
All users should select Private Networks, such as my home or work network and click Allow
access. For additional information on security and MongoDB, please see the Security Documentation (page 281).
Step 3: Connect to MongoDB. To connect to MongoDB through the mongo.exe shell, open another Command
Prompt. When connecting, specify the data directory if necessary. This step provides several example connection
commands.
If your MongoDB installation uses the default data directory, connect without specifying the data directory:
C:mongodbbinmongo.exe
If you installation uses a different data directory, specify the directory when connecting, as in this example:
C:mongodbbinmongod.exe --dbpath d:testmongodbdata
If your path includes spaces, enclose the entire path in double quotes. For example:
C:mongodbbinmongod.exe --dbpath "d:testmongo db data"
If you want to develop applications using .NET, see the documentation of C# and MongoDB20 for more information.
Step 4: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Also
consider the Production Notes (page 188) document before deploying MongoDB in a production environment.
Configure a Windows Service for MongoDB Enterprise
You can set up the MongoDB server as a Windows Service that starts automatically at boot time.
Step 1: Configure directories and files. Create a configuration file and a directory path for MongoDB log
output (logpath):
Create a specific directory for MongoDB log files:
md "C:Program FilesMongoDBlog"
In the Command Prompt, create a configuration file for the logpath option for MongoDB:
echo logpath="C:Program FilesMongoDBlogmongo.log" > "C:Program FilesMongoDBmongod.cfg"
20http://docs.mongodb.org/ecosystem/drivers/csharp
2.1. Installation Guides 37
42. MongoDB Documentation, Release 2.6.4
Step 2: Run the MongoDB service. Run all of the following commands in Command Prompt with “Administrative
Privileges:”
Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option.
"C:Program FilesMongoDBbinmongod.exe" --config "C:Program FilesMongoDBmongod.cfg" --install
Modify the path to the mongod.cfg file as needed.
To use an alternate dbpath, specify the path in the configuration file (e.g. C:Program
FilesMongoDBmongod.cfg) or on the command line with the --dbpath option.
If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is datadb.
If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service with
a unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient system
resources exist and your system design requires it.
Step 3: Stop or remove the MongoDB service as needed. To stop the MongoDB service use the following com-mand:
net stop MongoDB
To remove the MongoDB service use the following command:
"C:Program FilesMongoDBbinmongod.exe" --remove
Configure a Windows Service for MongoDB Enterprise
Note: There is a known issue for MongoDB 2.6.0, SERVER-1351521, which prevents the use of the instructions
in this section. For MongoDB 2.6.0, use Manually Create a Windows Service for MongoDB Enterprise (page 39) to
create a Windows Service for MongoDB.
You can set up the MongoDB server as a Windows Service that starts automatically at boot time.
Step 1: Configure directories and files. Create a configuration file and a directory path for MongoDB log
output (logpath):
Create a specific directory for MongoDB log files:
md "C:Program FilesMongoDBlog"
In the Command Prompt, create a configuration file for the logpath option for MongoDB:
echo logpath="C:Program FilesMongoDBlogmongo.log" > "C:Program FilesMongoDBmongod.cfg"
Step 2: Run the MongoDB service. Run all of the following commands in Command Prompt with “Administrative
Privileges:”
Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option.
"C:Program FilesMongoDBbinmongod.exe" --config "C:Program FilesMongoDBmongod.cfg" --install
21https://jira.mongodb.org/browse/SERVER-13515
38 Chapter 2. Install MongoDB
43. MongoDB Documentation, Release 2.6.4
Modify the path to the mongod.cfg file as needed.
To use an alternate dbpath, specify the path in the configuration file (e.g. C:Program
FilesMongoDBmongod.cfg) or on the command line with the --dbpath option.
If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is datadb.
If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service with
a unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient system
resources exist and your system design requires it.
Step 3: Stop or remove the MongoDB service as needed. To stop the MongoDB service use the following com-mand:
net stop MongoDB
To remove the MongoDB service use the following command:
"C:Program FilesMongoDBbinmongod.exe" --remove
Manually Create a Windows Service for MongoDB Enterprise
The following procedure assumes you have installed MongoDB using the MSI installer, with the default path
C:Program FilesMongoDB 2.6 Enterprise.
If you have installed in an alternative directory, you will need to adjust the paths as appropriate.
Step 1: Open an Administrator command prompt. Press Win + R, then type cmd, then press Ctrl + Shift
+ Enter.
Execute the remaining steps from the Administrator command prompt.
Step 2: Create directories. Create directories for your database and log files:
mkdir c:datadb
mkdir c:datalog
Step 3: Create a configuration file. Create a configuration file. This file can include any of the
configuration options for mongod, but must include a valid setting for logpath:
The following creates a configuration file, specifying both the logpath and the dbpath settings in the configuration
file:
echo logpath=c:datalogmongod.log> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"
echo dbpath=c:datadb>> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"
Step 4: Create the MongoDB service. Create the MongoDB service.
sc.exe create MongoDB binPath= ""C:Program FilesMongoDB 2.6 Enterprisebinmongod.exe" --service sc.exe requires a space between “=” and the configuration values (eg “binPath= ”), and a “” to escape double quotes.
If successfully created, the following log message will display:
2.1. Installation Guides 39
44. MongoDB Documentation, Release 2.6.4
[SC] CreateService SUCCESS
Step 5: Start the MongoDB service.
net start MongoDB
Step 6: Stop or remove the MongoDB service as needed. To stop the MongoDB service, use the following com-mand:
net stop MongoDB
To remove the MongoDB service, first stop the service and then run the following command:
sc.exe delete MongoDB
2.1.5 Verify Integrity of MongoDB Packages
Overview
The MongoDB release team digitally signs all software packages to certify that a particular MongoDB package is a
valid and unaltered MongoDB release.
Before installing MongoDB, you can validate packages using either a PGP signature or with MD5 and SHA checksums
of the MongoDB packages. The PGP signatures store an encrypted hash of the software package, that you can validate
to ensure that the package you have is consistent with the official package release. MongoDB also publishes MD5 and
SHA hashes of the official packages that you can use to confirm that you have a valid package.
Considerations
MongoDB signs each release branch with a different PGP key.
The public .asc and .pub key files for each branch are available for download. For example, the 2.2 keys are
available at the following URLs:
https://www.mongodb.org/static/pgp/server-2.2.asc
https://www.mongodb.org/static/pgp/server-2.2.pub
Replace 2.2 with the appropriate release number to download public key. Keys are available for all MongoDB
releases beginning with 2.2.
Procedures
Use PGP/GPG
Step 1: Download the MongoDB installation file. Download the binaries from
https://www.mongodb.org/downloads based on your environment.
For example, to download the 2.6.0 release for OS X through the shell, type this command:
curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz
40 Chapter 2. Install MongoDB
45. MongoDB Documentation, Release 2.6.4
Step 2: Download the public signature file.
curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz.sig
Step 3: Download then import the key file. If you have not downloaded and imported the key file, enter these
commands:
curl -LO https://www.mongodb.org/static/pgp/server-2.6.asc
gpg --import server-2.6.asc
You should receive this message:
gpg: key AAB2461C: public key "MongoDB 2.6 Release Signing Key <packaging@mongodb.com>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
Step 4: Verify the MongoDB installation file. Type this command:
gpg --verify mongodb-osx-x86_64-2.6.0.tgz.sig mongodb-osx-x86_64-2.6.0.tgz
You should receive this message:
gpg: Signature made Thu Mar 6 15:11:28 2014 EST using RSA key ID AAB2461C
gpg: Good signature from "MongoDB 2.6 Release Signing Key <packaging@mongodb.com>"
Download and import the key file, as described above, if you receive a message like this one:
gpg: Signature made Thu Mar 6 15:11:28 2014 EST using RSA key ID AAB2461C
gpg: Can't check signature: public key not found
gpg will return the following message if the package is properly signed, but you do not currently trust the signing key
in your local trustdb.
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: DFFA 3DCF 326E 302C 4787 673A 01C4 E7FA AAB2 461C
Use SHA
MongoDB provides checksums using both the SHA-1 and SHA-256 hash functions. You can use either, as you like.
Step 1: Download the MongoDB installation file. Download the binaries from
https://www.mongodb.org/downloads based on your environment.
For example, to download the 2.6.0 release for OS X through the shell, type this command:
curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz
Step 2: Download the SHA1 and SHA256 file.
curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.3.tgz.sha1
curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.3.tgz.sha256
2.1. Installation Guides 41
46. MongoDB Documentation, Release 2.6.4
Step 3: Use the SHA-256 checksum to verify the MongoDB package file. Compute the checksum of the package
file:
shasum mongodb-linux-x86_64-2.6.3.tgz
which will generate this result:
fe511ee40428edda3a507f70d2b91d16b0483674 mongodb-osx-x86_64-2.6.3.tgz
Enter this command:
cat mongodb-linux-x86_64-2.6.3.tgz.sha1
which will generate this result:
fe511ee40428edda3a507f70d2b91d16b0483674 mongodb-osx-x86_64-2.6.3.tgz
The output of the shasum and cat commands should be identical.
Step 3: Use the SHA-1 checksum to verify the MongoDB package file. Compute the checksum of the package
file:
shasum -a 256 mongodb-linux-x86_64-2.6.3.tgz
which will generate this result:
be3a5e9f4e9c8e954e9af7053776732387d2841a019185eaf2e52086d4d207a3 mongodb-osx-x86_64-2.6.3.tgz
Enter this command:
cat mongodb-linux-x86_64-2.6.3.tgz.sha256
which will generate this result:
be3a5e9f4e9c8e954e9af7053776732387d2841a019185eaf2e52086d4d207a3 mongodb-osx-x86_64-2.6.3.tgz
The output of the shasum and cat commands should be identical.
Use MD5
Step 1: Download the MongoDB installation file. Download the binaries from
https://www.mongodb.org/downloads based on your environment.
For example, to download the 2.6.0 release for OS X through the shell, type this command:
curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz
Step 2: Download the MD5 file.
curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz.md5
Step 3: Verify the checksum values for the MongoDB package file (Linux). Compute the checksum of the pack-age
file:
md5 mongodb-linux-x86_64-2.6.0.tgz
which will generate this result:
42 Chapter 2. Install MongoDB
47. MongoDB Documentation, Release 2.6.4
MD5 (mongodb-linux-x86_64-2.6.0.tgz) = a937d49881f90e1a024b58d642011dc4
Enter this command:
cat mongodb-linux-x86_64-2.6.0.tgz.md5
which will generate this result:
a937d49881f90e1a024b58d642011dc4
The output of the md5 and cat commands should be identical.
Step 4: Verify the MongoDB installation file (OS X). Compute the checksum of the package file:
md5sum -c mongodb-osx-x86_64-2.6.0.tgz.md5 mongodb-osx-x86_64-2.6.0.tgz
which will generate this result:
mongodb-osx-x86_64-2.6.0-rc1.tgz ok
2.2 First Steps with MongoDB
After you have installed MongoDB, consider the following documents as you begin to learn about MongoDB:
Getting Started with MongoDB (page 43) An introduction to the basic operation and use of MongoDB.
Generate Test Data (page 47) To support initial exploration, generate test data to facilitate testing.
2.2.1 Getting Started with MongoDB
This tutorial provides an introduction to basic database operations using the mongo shell. mongo is a part of the
standard MongoDB distribution and provides a full JavaScript environment with complete access to the JavaScript
language and all standard functions as well as a full database interface for MongoDB. See the mongo JavaScript API22
documentation and the mongo shell JavaScript Method Reference.
The tutorial assumes that you’re running MongoDB on a Linux or OS X operating system and that you have a running
database server; MongoDB does support Windows and provides a Windows distribution with identical operation.
For instructions on installing MongoDB and starting the database server, see the appropriate installation (page 5)
document.
Connect to a Database
In this section, you connect to the database server, which runs as mongod, and begin using the mongo shell to select
a logical database within the database instance and access the help text in the mongo shell.
Connect to a mongod
From a system prompt, start mongo by issuing the mongo command, as follows:
mongo
22http://api.mongodb.org/js
2.2. First Steps with MongoDB 43
48. MongoDB Documentation, Release 2.6.4
By default, mongo looks for a database server listening on port 27017 on the localhost interface. To connect to
a server on a different port or interface, use the --port and --host options.
Select a Database
After starting the mongo shell your session will use the test database by default. At any time, issue the following
operation at the mongo to report the name of the current database:
db
1. From the mongo shell, display the list of databases, with the following operation:
show dbs
2. Switch to a new database named mydb, with the following operation:
use mydb
3. Confirm that your session has the mydb database as context, by checking the value of the db object, which
returns the name of the current database, as follows:
db
At this point, if you issue the show dbs operation again, it will not include the mydb database. MongoDB
will not permanently create a database until you insert data into that database. The Create a Collection and
Insert Documents (page 44) section describes the process for inserting data.
New in version 2.4: show databases also returns a list of databases.
Display mongo Help
At any point, you can access help for the mongo shell using the following operation:
help
Furthermore, you can append the .help() method to some JavaScript methods, any cursor object, as well as the db
and db.collection objects to return additional help information.
Create a Collection and Insert Documents
In this section, you insert documents into a new collection named testData within the new database named mydb.
MongoDB will create a collection implicitly upon its first use. You do not need to create a collection before inserting
data. Furthermore, because MongoDB uses dynamic schemas (page 688), you also need not specify the structure of
your documents before inserting them into the collection.
1. From the mongo shell, confirm you are in the mydb database by issuing the following:
db
2. If mongo does not return mydb for the previous operation, set the context to the mydb database, with the
following operation:
use mydb
3. Create two documents named j and k by using the following sequence of JavaScript operations:
44 Chapter 2. Install MongoDB