mongodb-manual.pdf

940
MongoDB Documentation Release 3.0.4 MongoDB Documentation Project July 14, 2015

Upload: jorge-v-prestige

Post on 13-Jan-2016

17 views

Category:

Documents


0 download

TRANSCRIPT

  • MongoDB DocumentationRelease 3.0.4

    MongoDB Documentation Project

    July 14, 2015

  • 2

  • Contents

    1 Introduction to MongoDB 31.1 What is MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

    2 Install MongoDB 52.1 Recommended Operating Systems for Production Deployments . . . . . . . . . . . . . . . . . . . . 52.2 Other Supported Operating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.3 Installation Guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.4 First Steps with MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 552.5 Additional Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

    3 MongoDB CRUD Operations 573.1 MongoDB CRUD Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573.2 MongoDB CRUD Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603.3 MongoDB CRUD Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923.4 MongoDB CRUD Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

    4 Data Models 1434.1 Data Modeling Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1434.2 Data Modeling Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1454.3 Data Model Examples and Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1514.4 Data Model Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

    5 Administration 1835.1 Administration Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1835.2 Administration Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2205.3 Administration Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2875.4 Production Checklist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312

    6 Security 3176.1 Security Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3176.2 Security Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3196.3 Security Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3326.4 Security Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3986.5 Security Checklist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425

    7 Aggregation 4297.1 Aggregation Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4297.2 Aggregation Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4337.3 Aggregation Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446

    i

  • 7.4 Aggregation Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4637.5 Additional Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473

    8 Indexes 4758.1 Index Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4758.2 Index Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4808.3 Indexing Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5118.4 Indexing Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 546

    9 Replication 5539.1 Replication Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5539.2 Replication Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5579.3 Replica Set Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5969.4 Replication Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645

    10 Sharding 65510.1 Sharding Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65510.2 Sharding Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66110.3 Sharded Cluster Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68410.4 Sharding Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 730

    11 Frequently Asked Questions 73711.1 FAQ: MongoDB Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73711.2 FAQ: MongoDB for Application Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74011.3 FAQ: The mongo Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75011.4 FAQ: Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75211.5 FAQ: Sharding with MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75711.6 FAQ: Replication and Replica Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76211.7 FAQ: MongoDB Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76611.8 FAQ: Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77111.9 FAQ: MongoDB Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773

    12 Release Notes 77912.1 Current Stable Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77912.2 Previous Stable Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82112.3 Other MongoDB Release Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91812.4 MongoDB Version Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 919

    13 About MongoDB Documentation 92113.1 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92113.2 Editions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92113.3 Version and Revisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92213.4 Report an Issue or Make a Change Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92213.5 Contribute to the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 922

    ii

  • MongoDB Documentation, Release 3.0.4

    See About MongoDB Documentation (page 921) 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 PDFedition of all MongoDB Reference Material.

    1http://docs.mongodb.org/master/MongoDB-reference-manual.pdf

    Contents 1

  • MongoDB Documentation, Release 3.0.4

    2 Contents

  • CHAPTER 1

    Introduction to MongoDB

    Welcome to MongoDB. This document provides a brief introduction to MongoDB and some key concepts. See theinstallation 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 automaticscaling.

    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.

    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

  • MongoDB Documentation, Release 3.0.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, MongoDBs replication facility, called replica sets, provide:

    automatic failover.

    data redundancy.

    A replica set (page 553) is a group of MongoDB servers that maintain the same data set, providing redundancy andincreasing data availability.

    Automatic Scaling

    MongoDB provides horizontal scalability as part of its core functionality.

    Automatic sharding (page 655) 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

  • CHAPTER 2

    Install MongoDB

    MongoDB runs on most platforms and supports 64-bit architecture for production use and both 64-bit and 32-bitarchitectures for testing.

    2.1 Recommended Operating Systems for Production Deployments

    MongoDB MongoDB EnterpriseAmazon Linux supported supportedDebian 7.1 supported supportedRedHat / CentOS 6.2+ supported supportedSUSE 11 supported supportedUbuntu LTS 12.04 supported supportedUbuntu LTS 14.04 supported supportedWindows Server 2012 & 2012 R2 supported supported

    2.2 Other Supported Operating Systems

    MongoDB MongoDB EnterpriseMac OSX 10.6+ supportedRedHat / CentOS 5.5+ supportedRedHat / CentOS 5.7+ supported supportedRedHat / CentOS 7.0+ supported supportedSmartOS supportedSolaris 11 / SunOS 5.11 on x86 supportedWindows Server 2008 R2 supported supported

    2.3 Installation Guides

    See the Release Notes (page 779) 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 7) Install MongoDB on Red Hat Enterprise and related Linux systems using .rpmpackages.

    Install on Amazon Linux (page 13) Install MongoDB on Amazon Linux systems using .rpm packages.

    5

  • MongoDB Documentation, Release 3.0.4

    Install on SUSE (page 10) Install MongoDB on SUSE Linux systems using .rpm packages.

    Install on Ubuntu (page 16) Install MongoDB on Ubuntu Linux systems using .deb packages.

    Install on Debian (page 19) Install MongoDB on Debian systems using .deb packages.

    Install on Other Linux Systems (page 22) Install the official build of MongoDB on other Linux systems fromMongoDB archives.

    Install on OS X (page 25) Install the official build of MongoDB on OS X systems from Homebrew packages or fromMongoDB archives.

    Install on Windows (page 27) Install MongoDB on Windows systems and optionally start MongoDB as a Windowsservice.

    Install MongoDB Enterprise (page 33) MongoDB Enterprise is available for MongoDB Enterprise subscribers andincludes several additional features including support for SNMP monitoring, LDAP authentication, Kerberosauthentication, and System Event Auditing.

    Install MongoDB Enterprise on Red Hat (page 33) Install the MongoDB Enterprise build and required depen-dencies on Red Hat Enterprise or CentOS Systems using packages.

    Install MongoDB Enterprise on Ubuntu (page 38) Install the MongoDB Enterprise build and required depen-dencies on Ubuntu Linux Systems using packages.

    Install MongoDB Enterprise on Amazon AMI (page 48) Install the MongoDB Enterprise build and requireddependencies on Amazon Linux AMI.

    Install MongoDB Enterprise on Windows (page 49) Install the MongoDB Enterprise build and required de-pendencies using the .msi installer.

    2.3.1 Install on Linux

    These documents provide instructions to install MongoDB for various Linux systems.

    Recommended

    For the best installation experience, MongoDB provides packages for popular Linux distributions. These packages,which support specific platforms and provide improved performance and TLS/SSL support, are the preferred way torun MongoDB. The following guides detail the installation process for these systems:

    Install on Red Hat (page 7) Install MongoDB on Red Hat Enterprise and related Linux systems using .rpm pack-ages.

    Install on SUSE (page 10) Install MongoDB on SUSE Linux systems using .rpm packages.

    Install on Amazon Linux (page 13) Install MongoDB on Amazon Linux systems using .rpm packages.

    Install on Ubuntu (page 16) Install MongoDB on Ubuntu Linux systems using .deb packages.

    Install on Debian (page 19) Install MongoDB on Debian systems using .deb packages.

    For systems without supported packages, refer to the Manual Installation tutorial.

    Manual Installation

    For Linux systems without supported packages, MongoDB provides a generic Linux release. These versions of Mon-goDB dont include TLS/SSL, and may not perform as well as the targeted packages, but are compatible on mostcontemporary Linux systems. See the following guides for installation:

    6 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Install on Other Linux Systems (page 22) Install the official build of MongoDB on other Linux systems from Mon-goDB archives.

    Install MongoDB on Red Hat Enterprise or CentOS Linux

    Overview Use this tutorial to install MongoDB on Red Hat Enterprise Linux or CentOS Linux versions 5, 6, and 7using .rpm packages. While some of these distributions include their own MongoDB packages, the official MongoDBpackages are generally more up to date.

    This installation guide only supports 64-bit systems. See Platform Support (page 804) for details.

    Packages MongoDB provides officially supported packages in their own repository. This repository contains thefollowing 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, mongooplog, mongoperf, mongorestore, mongostat, andmongotop.

    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. Seethe Configuration File reference for documentation of settings available in the configuration file.

    As of version 3.0.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 661).You can use the mongod init script to derive your own mongos control script for use in such environments. See themongos reference for configuration details.

    Considerations This installation guide only supports 64-bit systems. See Platform Support (page 804) for details.

    The default /etc/mongod.conf configuration file supplied by the 3.0 series packages has bind_ip set to127.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

    2.3. Installation Guides 7

  • MongoDB Documentation, Release 3.0.4

    Step 1: Configure the package management system (yum). Create a/etc/yum.repos.d/mongodb-org-3.0.repo file so that you can install MongoDB directly, usingyum.

    Changed in version 3.0: MongoDB Linux packages for 3.0 are in a new repository.

    For the latest stable release of MongoDB Use the following repository file:

    [mongodb-org-3.0]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/gpgcheck=0enabled=1

    For versions of MongoDB earlier than 3.0 To install the packages from an earlier release series (page 919), suchas 2.4 or 2.6, you can specify the release series in the repository configuration. For example, to restrict your systemto the 2.6 release series, create a /etc/yum.repos.d/mongodb-org-2.6.repo file to hold the followingconfiguration information for the MongoDB 2.6 repository:

    [mongodb-org-2.6]name=MongoDB 2.6 Repositorybaseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/gpgcheck=0enabled=1

    .repo files for each release can also be found in the repository itself1. Remember that odd-numbered minor releaseversions (e.g. 2.5) are development versions and are unsuitable for production use.

    Step 2: Install the MongoDB packages and associated tools. When you install the packages, you choose whetherto 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

    To install a specific release of MongoDB, specify each component package individually and append the version numberto the package name, as in the following example:

    sudo yum install -y mongodb-org-3.0.4 mongodb-org-server-3.0.4 mongodb-org-shell-3.0.4 mongodb-org-mongos-3.0.4 mongodb-org-tools-3.0.4

    You can specify any available version of MongoDB. However yum will upgrade the packages when a newer versionbecomes available. To prevent unintended upgrades, pin the package. To pin a package, add the following excludedirective to your /etc/yum.conf file:

    exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

    Versions of the MongoDB packages before 2.6 use a different repo location. Refer to the version of the documentationappropriate for your MongoDB version.

    Run MongoDB

    Prerequisites1https://repo.mongodb.org/yum/redhat/

    8 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Configure SELinuxImportant: You must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red HatEnterprise Linux or CentOS Linux).

    To configure SELinux, administrators have three options:

    Note: All three options require root privileges. The first two options each requires a system reboot and may havelarger implications for your deployment.

    Disable SELinux entirely by changing the SELINUX setting to disabled in /etc/selinux/config.

    SELINUX=disabled

    Set SELinux to permissive mode in /etc/selinux/config by changing the SELINUX setting topermissive .

    SELINUX=permissive

    Note: You can use setenforce to change to permissive mode; this method does not require a reboot but isnot persistent.

    Enable access to the relevant ports (e.g. 27017) for SELinux if in enforcing mode. See Default MongoDBPort (page 418) for more information on MongoDBs default ports. For default settings, this can be accom-plished by running

    semanage port -a -t mongod_port_t -p tcp 27017

    Warning: On RHEL 7.0, if you change the data path, the default SELinux policies will prevent mongodfrom having write access on the new data path if you do not change the security context.

    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.

    Data Directories and Permissions Warning: On RHEL 7.0, if you change the data path, the default SELinux policies will prevent mongod fromhaving write access on the new data path if you do not change the security context.

    The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodbby default, and runs using the mongod user account. You can specify alternate log and data file directories in/etc/mongod.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 user 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

    2.3. Installation Guides 9

  • MongoDB Documentation, Release 3.0.4

    where 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 help you start using MongoDB, MongoDB provides Getting Started Guides invarious driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    Uninstall MongoDB To completely remove MongoDB from a system, you must remove the MongoDB applicationsthemselves, the configuration files, and any directories containing data and logs. The following section guides youthrough the necessary steps.

    Warning: This process will completely remove MongoDB, its configuration, and all databases. This process isnot reversible, so ensure that all of your configuration and data is backed up before proceeding.

    Step 1: Stop MongoDB. Stop the mongod process by issuing the following command:

    sudo service mongod stop

    Step 2: Remove Packages. Remove any MongoDB packages that you had previously installed.

    sudo yum erase $(rpm -qa | grep mongodb-org)

    Step 3: Remove Data Directories. Remove MongoDB databases and log files.

    sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongo

    Install MongoDB on SUSE

    Overview Use this tutorial to install MongoDB on SUSE Linux from .rpm packages. While SUSE distributionsinclude their own MongoDB packages, the official MongoDB packages are generally more up to date.

    This installation guide only supports 64-bit systems. See Platform Support (page 804) for details.

    10 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Packages MongoDB provides officially supported packages in their own repository. This repository contains thefollowing 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, mongooplog, mongoperf, mongorestore, mongostat, andmongotop.

    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. Seethe Configuration File reference for documentation of settings available in the configuration file.

    As of version 3.0.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 661).You can use the mongod init script to derive your own mongos control script for use in such environments. See themongos reference for configuration details.

    Considerations This installation guide only supports 64-bit systems. See Platform Support (page 804) for details.

    The default /etc/mongod.conf configuration file supplied by the 3.0 series packages has bind_ip set to127.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.

    Note: SUSE Linux Enterprise Server 11 and potentially other versions of SLES and other SUSE distributions shipwith virtual memory address space limited to 8GB by default. This must be adjusted in order to prevent virtual memoryallocation failures as the database grows.

    The SLES packages for MongoDB adjust these limits in the default scripts, but you will need to make this changemanually if you are using custom scripts and/or the tarball release rather than the SLES packages.

    Install MongoDB

    Step 1: Configure the package management system (zypper). Add the repository so that you can install Mon-goDB using zypper.

    Changed in version 3.0: MongoDB Linux packages for 3.0 are in a new repository.

    2.3. Installation Guides 11

  • MongoDB Documentation, Release 3.0.4

    For the latest stable release of MongoDB Use the following command:

    zypper addrepo --no-gpgcheck https://repo.mongodb.org/zypper/suse/11/mongodb-org/3.0/x86_64/ mongodb

    For versions of MongoDB earlier than 3.0 To install MongoDB packages from a previous release series (page 919),such as 2.6, you can specify the release series in the repository configuration. For example, to restrict your system tothe 2.6 release series, use the following command:

    zypper addrepo --no-gpgcheck http://downloads-distro.mongodb.org/repo/suse/os/x86_64/ mongodb

    Step 2: Install the MongoDB packages and associated tools. When you install the packages, you choose whetherto 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 zypper install mongodb-org

    To install a specific release of MongoDB, specify each component package individually and append the version numberto the package name, as in the following example:

    sudo zypper install mongodb-org-3.0.4 mongodb-org-server-3.0.4 mongodb-org-shell-3.0.4 mongodb-org-mongos-3.0.4 mongodb-org-tools-3.0.4

    You can specify any available version of MongoDB. However zypper will upgrade the packages when a newerversion becomes available. To prevent unintended upgrades, pin the packages by running the following command:

    sudo zypper addlock mongodb-org-3.0.4 mongodb-org-server-3.0.4 mongodb-org-shell-3.0.4 mongodb-org-mongos-3.0.4 mongodb-org-tools-3.0.4

    Previous versions of MongoDB packages use a different repository location. Refer to the version of the documentationappropriate for your MongoDB version.

    Run MongoDB 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 anddata file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional in-formation.

    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 user 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

    where 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

    12 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    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 help you start using MongoDB, MongoDB provides Getting Started Guides invarious driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    Uninstall MongoDB To completely remove MongoDB from a system, you must remove the MongoDB applicationsthemselves, the configuration files, and any directories containing data and logs. The following section guides youthrough the necessary steps.

    Warning: This process will completely remove MongoDB, its configuration, and all databases. This process isnot reversible, so ensure that all of your configuration and data is backed up before proceeding.

    Step 1: Stop MongoDB. Stop the mongod process by issuing the following command:

    sudo service mongod stop

    Step 2: Remove Packages. Remove any MongoDB packages that you had previously installed.

    sudo zypper remove $(rpm -qa | grep mongodb-org)

    Step 3: Remove Data Directories. Remove MongoDB databases and log files.

    sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongo

    Install MongoDB on Amazon Linux

    Overview Use this tutorial to install MongoDB on Amazon Linux from .rpm packages.

    This installation guide only supports 64-bit systems. See Platform Support (page 804) for details.

    Packages MongoDB provides officially supported packages in their own repository. This repository contains thefollowing packages:

    mongodb-org

    This package is a metapackage that will automatically install the four component packages listed below.

    2.3. Installation Guides 13

  • MongoDB Documentation, Release 3.0.4

    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, mongooplog, mongoperf, mongorestore, mongostat, andmongotop.

    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. Seethe Configuration File reference for documentation of settings available in the configuration file.

    As of version 3.0.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 661).You can use the mongod init script to derive your own mongos control script for use in such environments. See themongos reference for configuration details.

    Considerations This installation guide only supports 64-bit systems. See Platform Support (page 804) for details.

    The default /etc/mongod.conf configuration file supplied by the 3.0 series packages has bind_ip set to127.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-org-3.0.repo file so that you can install MongoDB directly, usingyum.

    Changed in version 3.0: MongoDB Linux packages for 3.0 are in a new repository.

    For the latest stable release of MongoDB Use the following repository file:

    [mongodb-org-3.0]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.0/x86_64/gpgcheck=0enabled=1

    For versions of MongoDB earlier than 3.0 To install the packages from an earlier release series (page 919), suchas 2.4 or 2.6, you can specify the release series in the repository configuration. For example, to restrict your systemto the 2.6 release series, create a /etc/yum.repos.d/mongodb-org-2.6.repo file to hold the followingconfiguration information for the MongoDB 2.6 repository:

    14 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    [mongodb-org-2.6]name=MongoDB 2.6 Repositorybaseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/gpgcheck=0enabled=1

    .repo files for each release can also be found in the repository itself2. Remember that odd-numbered minor releaseversions (e.g. 2.5) are development versions and are unsuitable for production use.

    Step 2: Install the MongoDB packages and associated tools. When you install the packages, you choose whetherto 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

    To install a specific release of MongoDB, specify each component package individually and append the version numberto the package name, as in the following example:

    sudo yum install -y mongodb-org-3.0.4 mongodb-org-server-3.0.4 mongodb-org-shell-3.0.4 mongodb-org-mongos-3.0.4 mongodb-org-tools-3.0.4

    You can specify any available version of MongoDB. However yum will upgrade the packages when a newer versionbecomes available. To prevent unintended upgrades, pin the package. To pin a package, add the following excludedirective to your /etc/yum.conf file:

    exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools

    Versions of the MongoDB packages before 2.6 use a different repo location. Refer to the version of the documentationappropriate for your MongoDB version.

    Run MongoDB 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 anddata file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional in-formation.

    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 user 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

    where 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

    2https://repo.mongodb.org/yum/redhat/

    2.3. Installation Guides 15

  • MongoDB Documentation, Release 3.0.4

    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 help you start using MongoDB, MongoDB provides Getting Started Guides invarious driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    Uninstall MongoDB To completely remove MongoDB from a system, you must remove the MongoDB applicationsthemselves, the configuration files, and any directories containing data and logs. The following section guides youthrough the necessary steps.

    Warning: This process will completely remove MongoDB, its configuration, and all databases. This process isnot reversible, so ensure that all of your configuration and data is backed up before proceeding.

    Step 1: Stop MongoDB. Stop the mongod process by issuing the following command:

    sudo service mongod stop

    Step 2: Remove Packages. Remove any MongoDB packages that you had previously installed.

    sudo yum erase $(rpm -qa | grep mongodb-org)

    Step 3: Remove Data Directories. Remove MongoDB databases and log files.

    sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongo

    Install MongoDB on Ubuntu

    Overview Use this tutorial to install MongoDB on LTS Ubuntu Linux systems from .deb packages. While Ubuntuincludes its own MongoDB packages, the official MongoDB packages are generally more up-to-date.

    Platform SupportMongoDB only provides packages for 64-bit long-term support Ubuntu releases. Currently, this means 12.04 LTS(Precise Pangolin) and 14.04 LTS (Trusty Tahr). While the packages may work with other Ubuntu releases, this is nota supported configuration.

    16 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Packages MongoDB provides officially supported packages in their own repository. This repository contains thefollowing 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, mongooplog, mongoperf, mongorestore, mongostat, andmongotop.

    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. Seethe Configuration File reference for documentation of settings available in the configuration file.

    As of version 3.0.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 661).You can use the mongod init script to derive your own mongos control script for use in such environments. See themongos reference for configuration details.

    Considerations MongoDB only provides packages for 64-bit long-term support Ubuntu releases. Currently, thismeans 12.04 LTS (Precise Pangolin) and 14.04 LTS (Trusty Tahr). While the packages may work with other Ubuntureleases, this is not a supported configuration.

    You cannot install this package concurrently with the mongodb, mongodb-server, or mongodb-clients pack-ages provided by Ubuntu.

    The default /etc/mongod.conf configuration file supplied by the 3.0 series packages has bind_ip set to127.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 withGPG keys. Issue the following command to import the MongoDB public GPG Key3:

    sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

    3https://docs.mongodb.org/10gen-gpg-key.asc

    2.3. Installation Guides 17

  • MongoDB Documentation, Release 3.0.4

    Step 2: Create a list file for MongoDB. Create the /etc/apt/sources.list.d/mongodb-org-3.0.listlist file using the following command:

    echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

    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 specificversion 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. To install a specific release, you must specify each component packageindividually along with the version number, as in the following example:

    sudo apt-get install -y mongodb-org=3.0.4 mongodb-org-server=3.0.4 mongodb-org-shell=3.0.4 mongodb-org-mongos=3.0.4 mongodb-org-tools=3.0.4

    If you only install mongodb-org=3.0.4 and do not include the component packages, the latest version of eachMongoDB package will be installed regardless of what version you specified.

    Pin a specific version of MongoDB. Although you can specify any available version of MongoDB, apt-get willupgrade the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. Topin the version of MongoDB at the currently installed version, issue the following command sequence:

    echo "mongodb-org hold" | sudo dpkg --set-selectionsecho "mongodb-org-server hold" | sudo dpkg --set-selectionsecho "mongodb-org-shell hold" | sudo dpkg --set-selectionsecho "mongodb-org-mongos hold" | sudo dpkg --set-selectionsecho "mongodb-org-tools hold" | sudo dpkg --set-selections

    Versions of the MongoDB packages before 2.6 use a different repository location. Refer to the version of the docu-mentation appropriate for your MongoDB version.

    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 anddata file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional in-formation.

    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 user access to these directories.

    Step 1: Start MongoDB. Issue the following command to start mongod:

    sudo service mongod start

    18 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Step 2: Verify that MongoDB has started successfully Verify that the mongod process has started successfullyby checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

    [initandlisten] waiting for connections on port

    where 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 help you start using MongoDB, MongoDB provides Getting Started Guides invarious driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    Uninstall MongoDB To completely remove MongoDB from a system, you must remove the MongoDB applicationsthemselves, the configuration files, and any directories containing data and logs. The following section guides youthrough the necessary steps.

    Warning: This process will completely remove MongoDB, its configuration, and all databases. This process isnot reversible, so ensure that all of your configuration and data is backed up before proceeding.

    Step 1: Stop MongoDB. Stop the mongod process by issuing the following command:

    sudo service mongod stop

    Step 2: Remove Packages. Remove any MongoDB packages that you had previously installed.

    sudo apt-get purge mongodb-org*

    Step 3: Remove Data Directories. Remove MongoDB databases and log files.

    sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongodb

    Install MongoDB on Debian

    Overview Use this tutorial to install MongoDB from .deb packages on Debian 7 Wheezy. While Debian includesits own MongoDB packages, the official MongoDB packages are more up to date.

    MongoDB only provides packages for 64-bit Debian Wheezy. These packages may work with other Debian releases,but this is not a supported configuration.

    2.3. Installation Guides 19

  • MongoDB Documentation, Release 3.0.4

    Packages MongoDB provides officially supported packages in their own repository. This repository contains thefollowing 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, mongooplog, mongoperf, mongorestore, mongostat, andmongotop.

    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. Seethe Configuration File reference for documentation of settings available in the configuration file.

    As of version 3.0.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 661).You can use the mongod init script to derive your own mongos control script for use in such environments. See themongos reference for configuration details.

    Considerations This installation guide only supports 64-bit systems. See Platform Support (page 804) for details.

    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/mongod.conf configuration file supplied by the 3.0 series packages has bind_ip set to127.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 andauthenticity by requiring that distributors sign packages with GPG keys.

    Step 1: Import the public key used by the package management system. Issue the following command to addthe MongoDB public GPG Key4 to the system key ring.

    sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

    4https://docs.mongodb.org/10gen-gpg-key.asc

    20 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Step 2: Create a /etc/apt/sources.list.d/mongodb-org-3.0.list file for MongoDB. Create thelist file using the following command:

    echo "deb http://repo.mongodb.org/apt/debian wheezy/mongodb-org/3.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

    Currently packages are only available for Debian 7 (Wheezy).

    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 specificversion 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. To install a specific release, you must specify each component packageindividually along with the version number, as in the following example:

    sudo apt-get install -y mongodb-org=3.0.4 mongodb-org-server=3.0.4 mongodb-org-shell=3.0.4 mongodb-org-mongos=3.0.4 mongodb-org-tools=3.0.4

    If you only install mongodb-org=3.0.4 and do not include the component packages, the latest version of eachMongoDB package will be installed regardless of what version you specified.

    Pin a specific version of MongoDB. Although you can specify any available version of MongoDB, apt-get willupgrade the packages when a newer version becomes available. To prevent unintended upgrades, pin the package. Topin the version of MongoDB at the currently installed version, issue the following command sequence:

    echo "mongodb-org hold" | sudo dpkg --set-selectionsecho "mongodb-org-server hold" | sudo dpkg --set-selectionsecho "mongodb-org-shell hold" | sudo dpkg --set-selectionsecho "mongodb-org-mongos hold" | sudo dpkg --set-selectionsecho "mongodb-org-tools hold" | sudo dpkg --set-selections

    Versions of the MongoDB packages before 2.6 use a different repository location. Refer to the version of the docu-mentation appropriate for your MongoDB version.

    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 anddata file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional in-formation.

    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 user access to these directories.

    Step 1: Start MongoDB. Issue the following command to start mongod:

    sudo service mongod start

    2.3. Installation Guides 21

  • MongoDB Documentation, Release 3.0.4

    Step 2: Verify that MongoDB has started successfully Verify that the mongod process has started successfullyby checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading

    [initandlisten] waiting for connections on port

    where 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 help you start using MongoDB, MongoDB provides Getting Started Guides invarious driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    Uninstall MongoDB To completely remove MongoDB from a system, you must remove the MongoDB applicationsthemselves, the configuration files, and any directories containing data and logs. The following section guides youthrough the necessary steps.

    Warning: This process will completely remove MongoDB, its configuration, and all databases. This process isnot reversible, so ensure that all of your configuration and data is backed up before proceeding.

    Step 1: Stop MongoDB. Stop the mongod process by issuing the following command:

    sudo service mongod stop

    Step 2: Remove Packages. Remove any MongoDB packages that you had previously installed.

    sudo apt-get purge mongodb-org*

    Step 3: Remove Data Directories. Remove MongoDB databases and log files.

    sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongodb

    Install MongoDB on Linux Systems

    Overview Compiled versions of MongoDB for Linux provide a simple option for installing MongoDB for otherLinux systems without supported packages.

    Considerations For production deployments, always run MongoDB on 64-bit systems.

    22 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Install MongoDB MongoDB provides archives for both 64-bit and 32-bit Linux. Follow the installation procedureappropriate for your system.

    Install for 64-bit Linux

    Step 1: Download the binary files for the desired release of MongoDB. Download the binaries fromhttps://www.mongodb.org/downloads.

    For example, to download the latest release through the shell, issue the following:

    curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.4.tgz

    Step 2: Extract the files from the downloaded archive. For example, from a system shell, you can extract throughthe tar command:

    tar -zxvf mongodb-linux-x86_64-3.0.4.tgz

    Step 3: Copy the extracted archive to the target directory. Copy the extracted folder to the location from whichMongoDB will run.

    mkdir -p mongodbcp -R -n mongodb-linux-x86_64-3.0.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 shells rc file (e.g. ~/.bashrc):

    export PATH=/bin:$PATH

    Replace 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 fromhttps://www.mongodb.org/downloads.

    For example, to download the latest release through the shell, issue the following: .. include:: /includes/release/curl-release-linux-i686.rst

    Step 2: Extract the files from the downloaded archive. For example, from a system shell, you can extract throughthe tar command:

    tar -zxvf mongodb-linux-i686-3.0.4.tgz

    Step 3: Copy the extracted archive to the target directory. Copy the extracted folder to the location from whichMongoDB will run.

    mkdir -p mongodbcp -R -n mongodb-linux-i686-3.0.4/ mongodb

    2.3. Installation Guides 23

  • MongoDB Documentation, Release 3.0.4

    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 shells rc file (e.g. ~/.bashrc):

    export PATH=/bin:$PATH

    Replace 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 whichthe mongod process will write data. By default, the mongod process uses the /data/db directory. If you create adirectory other than this one, you must specify that directory in the dbpath option when starting the mongod processlater 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 useraccount 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 thepath 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 youuse 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 fullpath to the mongod binary at the system prompt:

    /mongod

    Specify the path of the data directory If you do not use the default data directory (i.e., /data/db), specify thepath to the data directory using the --dbpath option:

    mongod --dbpath

    Step 4: Begin using MongoDB. To help you start using MongoDB, MongoDB provides Getting Started Guides invarious driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    24 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    2.3.2 Install MongoDB on OS X

    Overview

    Use this tutorial to install MongoDB on OS X systems.

    Platform SupportStarting in version 3.0, MongoDB only supports OS X versions 10.7 (Lion) on Intel x86-64 and later.

    MongoDB is available through the popular OS X package manager Homebrew5 or through the MongoDB Downloadsite6.

    Install MongoDB

    You can install MongoDB with Homebrew7 or manually. This section describes both.

    Install MongoDB with Homebrew

    Homebrew8 installs binary packages based on published formulae. This section describes how to update brew tothe latest packages and install MongoDB. Homebrew requires some initial setup and configuration, which is beyondthe scope of this document.

    Step 1: Update Homebrews package database.

    In a system shell, issue the following command:

    brew update

    Step 2: Install MongoDB.

    You can install MongoDB 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 TLS/SSL Support To build MongoDB from the source files and includeTLS/SSL support, issue the following from a system shell:

    brew install mongodb --with-openssl

    5http://brew.sh/6http://www.mongodb.org/downloads7http://brew.sh/8http://brew.sh/

    2.3. Installation Guides 25

  • MongoDB Documentation, Release 3.0.4

    Install the Latest Development Release of MongoDB To install the latest development release for use in testingand 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 25).

    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 https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.0.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-osx-x86_64-3.0.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 mongodbcp -R -n mongodb-osx-x86_64-3.0.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, youcan modify your PATH.

    For example, you can add the following line to your shells rc file (e.g. ~/.bashrc):

    export PATH=/bin:$PATH

    Replace 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. Bydefault, the mongod process uses the /data/db directory. If you create a directory other than this one, you mustspecify 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:

    26 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.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 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 thedata directory. See the following examples.

    Run without specifying paths If your system PATH variable includes the location of the mongod binary and if youuse 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 fullpath to the mongod binary at the system prompt:

    /mongod

    Specify the path of the data directory If you do not use the default data directory (i.e., /data/db), specify thepath to the data directory using the --dbpath option:

    mongod --dbpath

    Step 4: Begin using MongoDB.

    To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    2.3.3 Install MongoDB on Windows

    Overview

    Use this tutorial to install MongoDB on Windows systems.

    Platform SupportStarting in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to usemore recent releases of MongoDB.

    Important: If you are running any edition of Windows Server 2008 R2 or Windows 7, please install a hotfix to

    2.3. Installation Guides 27

  • MongoDB Documentation, Release 3.0.4

    resolve an issue with memory mapped files on Windows9.

    Requirements

    On Windows MongoDB requires Windows Server 2008 R2, Windows Vista, or later. The .msi installer includes allother software dependencies and will automatically upgrade any older version of MongoDB installed using an .msifile.

    Get MongoDB

    Step 1: Determine which MongoDB build you need.

    There are three builds of MongoDB for Windows:

    MongoDB for Windows 64-bit runs only on Windows Server 2008 R2, Windows 7 64-bit, and newer versions ofWindows. This build takes advantage of recent enhancements to the Windows Platform and cannot operate on olderversions of Windows.

    MongoDB for Windows 32-bit runs on any 32-bit version of Windows newer than Windows Vista. 32-bit versionsof MongoDB are only intended for older systems and for use in testing and development systems. 32-bit versions ofMongoDB only support databases smaller than 2GB.

    MongoDB for Windows 64-bit Legacy runs on Windows Vista, Windows Server 2003, and Windows Server 2008and does not include recent performance enhancements.

    To find which version of Windows you are running, enter the following commands in the Command Prompt or Pow-ershell:

    wmic os get captionwmic os get osarchitecture

    Step 2: Download MongoDB for Windows.

    Download the latest production release of MongoDB from the MongoDB downloads page10. Ensure you downloadthe correct version of MongoDB for your Windows system. The 64-bit versions of MongoDB do not work with 32-bitWindows.

    Install MongoDB

    Interactive Installation

    Step 1: Install MongoDB for Windows.

    In Windows Explorer, locate the downloaded MongoDB .msi file, which typically is located in the defaultDownloads folder. Double-click the .msi file. A set of screens will appear to guide you through the installa-tion process.

    You may specify an installation directory if you choose the Custom installation option.

    9http://support.microsoft.com/kb/273128410http://www.mongodb.org/downloads

    28 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Note: These instructions assume that you have installed MongoDB to C:\mongodb.

    MongoDB is self-contained and does not have any other system dependencies. You can run MongoDB from any folderyou choose. You may install MongoDB in any folder (e.g. D:\test\mongodb).

    Unattended Installation

    You may install MongoDB unattended on Windows from the command line using msiexec.exe.

    Step 1: Open an Administrator command prompt.

    Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Adminis-trator.

    Execute the remaining steps from the Administrator command prompt.

    Step 2: Install MongoDB for Windows.

    Change to the directory containing the .msi installation binary of your choice and invoke:

    msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.0.4-signed.msi ^INSTALLLOCATION="C:\mongodb" ^ADDLOCAL="all"

    You can specify the installation location for the executable by modifying the INSTALLLOCATION value.

    By default, this method installs all MongoDB binaries. To install specific MongoDB component sets, you can specifythem in the ADDLOCAL argument using a comma-separated list including one or more of the following componentsets:

    Component Set BinariesServer mongod.exeRouter mongos.exeClient mongo.exeMonitoringTools mongostat.exe, mongotop.exeImportExportTools mongodump.exe, mongorestore.exe, mongoexport.exe,

    mongoimport.exeMiscellaneousTools bsondump.exe, mongofiles.exe, mongooplog.exe, mongoperf.exe

    For instance, to install only the MongoDB utilities, invoke:

    msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.0.4-signed.msi ^INSTALLLOCATION="C:\mongodb" ^ADDLOCAL="MonitoringTools,ImportExportTools,MiscellaneousTools"

    Run MongoDB

    Warning: Do not make mongod.exe visible on public networks without running in Secure Mode with theauth setting. MongoDB is designed to be run in trusted environments, and the database does not enable SecureMode by default.

    2.3. Installation Guides 29

  • MongoDB Documentation, Release 3.0.4

    Step 1: Set up the MongoDB environment.

    MongoDB requires a data directory to store all data. MongoDBs default data directory path is \data\db. Createthis folder using the following commands from a Command Prompt:

    md \data\db

    You can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:

    C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\data

    If your path includes spaces, enclose the entire path in double quotes, for example:

    C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"

    You may also specify the dbpath in a configuration file.

    Step 2: Start MongoDB.

    To start MongoDB, run mongod.exe. For example, from the Command Prompt:

    C:\mongodb\bin\mongod.exe

    This starts the main MongoDB database process. The waiting for connections message in the consoleoutput 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 blockingsome features of C:\mongodb\bin\mongod.exe from communicating on networks. All users should selectPrivate Networks, such as my home or work network and click Allow access. For additionalinformation on security and MongoDB, please see the Security Documentation (page 317).

    Step 3: Connect to MongoDB.

    To connect to MongoDB through the mongo.exe shell, open another Command Prompt.

    C:\mongodb\bin\mongo.exe

    If you want to develop applications using .NET, see the documentation of C# and MongoDB11 for more information.

    Step 4: Begin using MongoDB.

    To help you start using MongoDB, MongoDB provides Getting Started Guides in various driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    Configure a Windows Service for MongoDB

    Step 1: Open an Administrator command prompt.

    Press the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Adminis-trator.

    11https://docs.mongodb.org/ecosystem/drivers/csharp

    30 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    Execute the remaining steps from the Administrator command prompt.

    Step 2: Create directories.

    Create directories for your database and log files:

    mkdir c:\data\dbmkdir c:\data\log

    Step 3: Create a configuration file.

    Create a configuration file. The file must set systemLog.path. Include additional configuration optionsas appropriate.

    For example, create a file at C:\mongodb\mongod.cfg that specifies both systemLog.path andstorage.dbPath:

    systemLog:destination: filepath: c:\data\log\mongod.log

    storage:dbPath: c:\data\db

    Step 4: Install the MongoDB service.

    Important: Run all of the following commands in Command Prompt with Administrative Privileges.

    Install the MongoDB service by starting mongod.exe with the --install option and the -config option tospecify the previously created configuration file.

    "C:\mongodb\bin\mongod.exe" --config "C:\mongodb\mongod.cfg" --install

    To use an alternate dbpath, specify the path in the configuration file (e.g. C:\mongodb\mongod.cfg) or on thecommand line with the --dbpath option.

    If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service witha unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient systemresources exist and your system design requires it.

    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 use the following command:

    2.3. Installation Guides 31

  • MongoDB Documentation, Release 3.0.4

    "C:\mongodb\bin\mongod.exe" --remove

    Manually Create a Windows Service for MongoDB

    You can set up the MongoDB server as a Windows Service that starts automatically at boot time.

    The following procedure assumes you have installed MongoDB using the .msi installer with the pathC:\mongodb\.

    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 the Win key, type cmd.exe, and press Ctrl + Shift + Enter to run the Command Prompt as Adminis-trator.

    Execute the remaining steps from the Administrator command prompt.

    Step 2: Create directories.

    Create directories for your database and log files:

    mkdir c:\data\dbmkdir c:\data\log

    Step 3: Create a configuration file.

    Create a configuration file. The file must set systemLog.path. Include additional configuration optionsas appropriate.

    For example, create a file at C:\mongodb\mongod.cfg that specifies both systemLog.path andstorage.dbPath:

    systemLog:destination: filepath: c:\data\log\mongod.log

    storage:dbPath: c:\data\db

    Step 4: Create the MongoDB service.

    Create the MongoDB service.

    sc.exe create MongoDB binPath= "C:\mongodb\bin\mongod.exe --service --config=\"C:\mongodb\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

    sc.exe requires a space between = and the configuration values (eg binPath= ), and a \ to escape doublequotes.

    If successfully created, the following log message will display:

    [SC] CreateService SUCCESS

    32 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    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

    Additional Resources

    MongoDB for Developers Free Course12

    MongoDB for .NET Developers Free Online Course13

    MongoDB Architecture Guide14

    2.3.4 Install MongoDB Enterprise

    These documents provide instructions to install MongoDB Enterprise for Linux and Windows Systems.

    Install MongoDB Enterprise on Red Hat (page 33) Install the MongoDB Enterprise build and required dependen-cies on Red Hat Enterprise or CentOS Systems using packages.

    Install MongoDB Enterprise on Ubuntu (page 38) Install the MongoDB Enterprise build and required dependencieson Ubuntu Linux Systems using packages.

    Install MongoDB Enterprise on Debian (page 41) Install the MongoDB Enterprise build and required dependencieson Debian Linux Systems using packages.

    Install MongoDB Enterprise on SUSE (page 45) Install the MongoDB Enterprise build and required dependencieson SUSE Enterprise Linux.

    Install MongoDB Enterprise on Amazon AMI (page 48) Install the MongoDB Enterprise build and required depen-dencies on Amazon Linux AMI.

    Install MongoDB Enterprise on Windows (page 49) 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 Enterprise15 on Red Hat Enterprise Linux or CentOS Linux versions 5, 6, and 7from .rpm packages.

    This installation guide only supports 64-bit systems. See Platform Support (page 804) for details.12https://university.mongodb.com/courses/M101P/about?jmp=docs13https://university.mongodb.com/courses/M101N/about?jmp=docs14https://www.mongodb.com/lp/white-paper/architecture-guide?jmp=docs15https://www.mongodb.com/products/mongodb-enterprise-advanced?jmp=docs

    2.3. Installation Guides 33

  • MongoDB Documentation, Release 3.0.4

    Packages

    MongoDB provides officially supported Enterprise packages in their own repository. This repository contains thefollowing 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. Seethe Configuration File reference for documentation of settings available in the configuration file.

    As of version 3.0.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 661).You can use the mongod init script to derive your own mongos control script.

    Considerations

    MongoDB only provides Enterprise packages for 64-bit builds of Red Hat Enterprise Linux and CentOS Linux ver-sions 5, 6, and 7.

    Use the provided distribution packages as described in this page if possible. These packages will automatically installall of MongoDBs dependencies, and are the recommended installation method.

    To manually install all dependencies, run the appropriate command for your Red Hat/CentOS version.

    Version 5

    yum install perl cyrus-sasl-lib krb5-libs lm_sensors net-snmp-libs openssl \popt rpm-libs tcp_wrappers zlib

    Version 6

    yum install cyrus-sasl-lib krb5-libs net-snmp-libs openssl

    Version 7

    yum install cyrus-sasl-lib krb5-libs lm_sensors-libs net-snmp-agent-libs \net-snmp-libs openssl-libs rpm-libs tcp_wrappers-libs

    34 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    The default /etc/mongod.conf configuration file supplied by the 3.0 series packages has bind_ip set to127.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 previousone. This procedure describes how to do both.

    Step 1: Configure repository. Create an /etc/yum.repos.d/mongodb-enterprise.repo file so thatyou can install MongoDB enterprise directly, using yum.

    For the latest stable release of MongoDB Enterprise Use the following repository file:

    [mongodb-enterprise]name=MongoDB Enterprise Repositorybaseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/stable/$basearch/gpgcheck=0enabled=1

    For specific version of MongoDB Enterprise To install MongoDB Enterprise packages from a specific release se-ries (page 919), such as 2.4 or 2.6, you can specify the release series in the repository configuration. For example, to re-strict your system to the 2.6 release series, create a /etc/yum.repos.d/mongodb-enterprise-2.6.repofile to hold the following configuration information for the MongoDB Enterprise 2.6 repository:

    [mongodb-enterprise-2.6]name=MongoDB Enterprise 2.6 Repositorybaseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/2.6/$basearch/gpgcheck=0enabled=1

    .repo files for each release can also be found in the repository itself16. Remember that odd-numbered minor releaseversions (e.g. 2.5) are development versions and are unsuitable for production deployment.

    Step 2: Install the MongoDB Enterprise packages and associated tools. You can install either the latest stableversion of MongoDB Enterprise or a specific version of MongoDB Enterprise.

    To install the latest stable version of MongoDB Enterprise, issue the following command:

    sudo yum install -y mongodb-enterprise

    Step 3: Optional: Manage Installed Version

    Install a specific release of MongoDB Enterprise. Specify each component package individually and append theversion 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-2.6.1 mongodb-enterprise-mongos-2.6.1 mongodb-enterprise-tools-2.6.1

    16https://repo.mongodb.com/yum/redhat/

    2.3. Installation Guides 35

  • MongoDB Documentation, Release 3.0.4

    Pin a specific version of MongoDB Enterprise. Although you can specify any available version of MongoDBEnterprise, 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,mongodb-enterprise-tools

    Previous versions of MongoDB packages use different naming conventions. See the 2.4 version of documentation formore information17.

    Step 4: When the install completes, you can run MongoDB.

    Run MongoDB Enterprise

    Prerequisites

    Configure SELinuxImportant: You must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red HatEnterprise Linux or CentOS Linux).

    To configure SELinux, administrators have three options:

    Note: All three options require root privileges. The first two options each requires a system reboot and may havelarger implications for your deployment.

    Disable SELinux entirely by changing the SELINUX setting to disabled in /etc/selinux/config.

    SELINUX=disabled

    Set SELinux to permissive mode in /etc/selinux/config by changing the SELINUX setting topermissive .

    SELINUX=permissive

    Note: You can use setenforce to change to permissive mode; this method does not require a reboot but isnot persistent.

    Enable access to the relevant ports (e.g. 27017) for SELinux if in enforcing mode. See Default MongoDBPort (page 418) for more information on MongoDBs default ports. For default settings, this can be accom-plished by running

    semanage port -a -t mongod_port_t -p tcp 27017

    Warning: On RHEL 7.0, if you change the data path, the default SELinux policies will prevent mongodfrom having write access on the new data path if you do not change the security context.

    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.

    Data Directories and Permissions Warning: On RHEL 7.0, if you change the data path, the default SELinux policies will prevent mongod fromhaving write access on the new data path if you do not change the security context.

    17http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-linux

    36 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.4

    The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodbby default, and runs using the mongod user account. You can specify alternate log and data file directories in/etc/mongod.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 user 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

    where 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 help you start using MongoDB, MongoDB provides Getting Started Guides invarious driver editions. See getting-started for the available editions.

    Before deploying MongoDB in a production environment, consider the Production Notes (page 197) document.

    Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.

    Uninstall MongoDB

    To completely remove MongoDB from a system, you must remove the MongoDB applications themselves, the con-figuration files, and any directories containing data and logs. The following section guides you through the necessarysteps.

    Warning: This process will completely remove MongoDB, its configuration, and all databases. This process isnot reversible, so ensure that all of your configuration and data is backed up before proceeding.

    Step 1: Stop MongoDB. Stop the mongod process by issuing the following command:

    2.3. Installation Guides 37

  • MongoDB Documentation, Release 3.0.4

    sudo service mongod stop

    Step 2: Remove Packages. Remove any MongoDB packages that you had previously installed.

    sudo yum erase $(rpm -qa | grep mongodb-enterprise)

    Step 3: Remove Data Directories. Remove MongoDB databases and log files.

    sudo rm -r /var/log/mongodbsudo rm -r /var/lib/mongo

    Install MongoDB Enterprise on Ubuntu

    Overview

    Use this tutorial to install MongoDB Enterprise18 on LTS Ubuntu Linux systems from .deb packages.

    Platform SupportMongoDB only provides packages for 64-bit long-term support Ubuntu releases. Currently, this means 12.04 LTS(Precise Pangolin) and 14.04 LTS (Trusty Tahr). While the packages may work with other Ubuntu releases, this is nota supported configuration.

    Packages

    MongoDB provides officially supported Enterprise packages in their own repository. This repository contains thefollowing 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.

    18https://www.mongodb.com/products/mongodb-enterprise-advanced?jmp=docs

    38 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 3.0.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. Seethe Configuration File reference for documentation of settings available in the configuration file.

    As of version 3.0.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 661).You can use the mongod init script to derive your own mongos control script.

    Considerations

    MongoDB only provides packages for 64-bit long-term support Ubuntu releases. Currently, this means 12.04 LTS(Precise Pangolin) and 14.04 LTS (Trusty Tahr). While the packages may work with other Ubuntu releases, this is nota supported configuration.

    Changed in version 2.6: The package structure and names have changed as of version 2.6. For