MongoDB Manual

821
MongoDB Documentation Release 2.6.4 MongoDB Documentation Project August 22, 2014

description

Mongo

Transcript of MongoDB Manual

  • MongoDB DocumentationRelease 2.6.4

    MongoDB Documentation Project

    August 22, 2014

  • 2

  • Contents

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

    2 Install MongoDB 52.1 Installation Guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 First Steps with MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

    3 MongoDB CRUD Operations 473.1 MongoDB CRUD Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473.2 MongoDB CRUD Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493.3 MongoDB CRUD Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803.4 MongoDB CRUD Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

    4 Data Models 1234.1 Data Modeling Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1234.2 Data Modeling Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1254.3 Data Model Examples and Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1324.4 Data Model Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150

    5 Administration 1635.1 Administration Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1635.2 Administration Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1975.3 Administration Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256

    6 Security 2676.1 Security Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2676.2 Security Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2696.3 Security Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2826.4 Security Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348

    7 Aggregation 3757.1 Aggregation Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3757.2 Aggregation Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3797.3 Aggregation Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3917.4 Aggregation Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 407

    8 Indexes 4198.1 Index Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4198.2 Index Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424

    i

  • 8.3 Indexing Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4528.4 Indexing Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488

    9 Replication 4919.1 Replication Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4919.2 Replication Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4959.3 Replica Set Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5319.4 Replication Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580

    10 Sharding 59310.1 Sharding Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59310.2 Sharding Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59910.3 Sharded Cluster Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62010.4 Sharding Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 664

    11 Frequently Asked Questions 67311.1 FAQ: MongoDB Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67311.2 FAQ: MongoDB for Application Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67611.3 FAQ: The mongo Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68611.4 FAQ: Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68811.5 FAQ: Sharding with MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69211.6 FAQ: Replication and Replica Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69711.7 FAQ: MongoDB Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70011.8 FAQ: Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70411.9 FAQ: MongoDB Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 706

    12 Release Notes 71112.1 Current Stable Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71112.2 Previous Stable Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74812.3 Other MongoDB Release Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79312.4 MongoDB Version Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 794

    13 About MongoDB Documentation 79513.1 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79513.2 Editions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79513.3 Version and Revisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79613.4 Report an Issue or Make a Change Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79613.5 Contribute to the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796

    Index 813

    ii

  • MongoDB Documentation, Release 2.6.4

    See About MongoDB Documentation (page 795) 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 2.6.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.

    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

  • 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, MongoDBs replication facility, called replica sets, provide:

    automatic failover.

    data redundancy.

    A replica set (page 491) 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 593) 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 both 32-bit and 64-bit architectures.

    2.1 Installation Guides

    See the Release Notes (page 711) 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 11) Install MongoDB on Debian systems using .deb packages.

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

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

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

    Install MongoDB Enterprise (page 23) 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 23) Install the MongoDB Enterprise build and required depen-dencies on Red Hat Enterprise or CentOS Systems using packages.

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

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

    Install MongoDB Enterprise on SUSE (page 30) Install the MongoDB Enterprise build and required depen-dencies on SUSE Enterprise Linux.

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

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

    5

  • 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 theinstallation process for these systems:

    Install on Red Hat (page 6) Install MongoDB on Red Hat Enterprise, CentOS, Fedora and related Linux systemsusing .rpm packages.

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

    Install on Debian (page 11) 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 thefollowing guide:

    Install on Other Linux Systems (page 13) 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, ora related system. The tutorial uses .rpm packages to install. While some of these distributions include their ownMongoDB packages, the official MongoDB packages are generally more up to date.

    Packages MongoDB provides packages of the officially supported MongoDB builds in its own repository. Thisrepository 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

  • 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.

    The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. Seehttp://docs.mongodb.org/manualreference/configuration-options for documentation of theconfiguration file.

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

    Warning: With the introduction of systemd in Fedora 15, the control scripts included in the packages availablein the MongoDB downloads repository are not compatible with Fedora systems. A correction is forthcoming,see SERVER-7285a for more information, and in the mean time use your own control scripts or install using theprocedure outlined in Install MongoDB on Linux Systems (page 13).

    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 .deb package has bind_ip setto 127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.

    Install MongoDB

    Step 1: Configure the package management system (YUM). Create a /etc/yum.repos.d/mongodb.repofile 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 Repositorybaseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/gpgcheck=0enabled=1

    If you are running a 32-bit system, which is not recommended for production deployments, use the following config-uration:

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

    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 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 that installs the 2.6.1 release of MongoDB:

    sudo yum install mongodb-org-2.6.1 mongodb-org-server-2.6.1 mongodb-org-shell-2.6.1 mongodb-org-mongos-2.6.1 mongodb-org-tools-2.6.1

    2.1. Installation Guides 7

  • MongoDB Documentation, Release 2.6.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

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

    Run MongoDBImportant: You must configure SELinux to allow MongoDB to start on Fedora systems. Administrators have twooptions:

    enable access to the relevant ports (e.g. 27017) for SELinux. See Configuration Options (page 276) for moreinformation on MongoDBs default ports (page 367).

    disable SELinux entirely. This requires a system reboot and may have larger implications for your deployment.

    The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongo, and runsusing the mongod user account. If you change the user that runs the MongoDB process, you must modify the accesscontrol rights to the /var/lib/mongodb and /var/log/mongodb 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.

    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/mongo/mongod.log file.

    Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 40). Alsoconsider the Production Notes (page 180) document before deploying MongoDB in a production environment.

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

    8 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    Install MongoDB on Ubuntu

    Overview Use this tutorial to install MongoDB on Ubuntu Linux systems. The tutorial uses .deb packages toinstall. While Ubuntu includes its own MongoDB packages, the official MongoDB packages are generally moreup-to-date.

    Note: If you use an older Ubuntu that does not use Upstart (i.e. any version before 9.10 Karmic), please follow theinstructions on the Install MongoDB on Debian (page 11) tutorial.

    Packages MongoDB provides packages of the officially supported MongoDB builds in its own repository. Thisrepository 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.

    The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. Seehttp://docs.mongodb.org/manualreference/configuration-options for documentation of theconfiguration file.

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

    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 .deb package has bind_ip setto 127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.

    Install MongoDB

    2.1. Installation Guides 9

  • MongoDB Documentation, Release 2.6.4

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

    echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.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 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:

    apt-get install mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1

    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

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

    Run MongoDB The MongoDB instance stores its data files in /var/lib/mongodb and its log files in/var/log/mongodb, and runs using the mongodb user account. If you change the user that runs the Mon-goDB process, you must modify the access control rights to the /var/lib/mongodb and /var/log/mongodbdirectories.

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

    2http://docs.mongodb.org/10gen-gpg-key.asc3http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-ubuntu

    10 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    sudo service mongod start

    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.

    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 40). Alsoconsider the Production Notes (page 180) document before deploying MongoDB in a production environment.

    Install MongoDB on Debian

    Overview Use this tutorial to install MongoDB on Debian systems. The tutorial uses .deb packages to install.While some Debian distributions include their own MongoDB packages, the official MongoDB packages are generallymore up to date.

    Note: This tutorial applies to both Debian systems and versions of Ubuntu Linux prior to 9.10 Karmic which donot 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 its own repository. Thisrepository 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 11

  • MongoDB Documentation, Release 2.6.4

    Control Scripts The mongodb-org package includes various control scripts, including the init script/etc/init.d/mongod.

    The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. Seehttp://docs.mongodb.org/manualreference/configuration-options for documentation of theconfiguration file.

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

    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 .deb package has bind_ip setto 127.0.0.1 by default. Modify this setting as needed for your environment before initializing a replica set.

    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

    Step 2: Create a /etc/apt/sources.list.d/mongodb.list file for MongoDB. Create the list file usingthe following command:

    echo 'deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.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 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:

    apt-get install mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-mongos=2.6.1 mongodb-org-tools=2.6.1

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

    12 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    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

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

    Run MongoDB The MongoDB instance stores its data files in /var/lib/mongo and its log files in/var/log/mongo, and runs using the mongod user account. If you change the user that runs the MongoDBprocess, you must modify the access control rights to the /var/lib/mongo and /var/log/mongo 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 successfullyby checking the contents of the log file at /var/log/mongodb/mongod.log.

    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 40). Alsoconsider the Production Notes (page 180) 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 otherLinux 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 procedureappropriate for your system.

    Install for 64-bit Linux5http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-ubuntu

    2.1. Installation Guides 13

  • MongoDB Documentation, Release 2.6.4

    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 http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.3.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-2.6.3.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-2.6.3/ 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:

    curl -O http://downloads.mongodb.org/linux/mongodb-linux-i686-2.6.3.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-i686-2.6.3.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-2.6.3/ mongodb

    14 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.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: Stop MongoDB as needed. To stop MongoDB, press Control+C in the terminal where the mongodinstance is running.

    Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 40). Alsoconsider the Production Notes (page 180) document before deploying MongoDB in a production environment.

    2.1. Installation Guides 15

  • MongoDB Documentation, Release 2.6.4

    2.1.2 Install MongoDB on OS X

    Overview

    Use this tutorial to install MongoDB on on OS X systems.

    Platform SupportStarting 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 Downloadsite7.

    Install MongoDB

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

    Install MongoDB with Homebrew

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

    6http://brew.sh/7http://www.mongodb.org/downloads8http://brew.sh/9http://brew.sh/

    16 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.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 16).

    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.3.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-2.6.3.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-2.6.3/ 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:

    2.1. Installation Guides 17

  • 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 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: 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 40). Also consider the Production Notes(page 180) 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 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.

    18 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    Important: If you are running any edition of Windows Server 2008 R2 or Windows 7, please install a hotfix toresolve 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 764-bit, and newer versions of Windows. This build takes advantage of recent enhancements to the Windows Platformand cannot operate on older versions of Windows.

    MongoDB for Windows 64-bit runs on any 64-bit version of Windows newer than Windows XP, including WindowsServer 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 ofMongoDB are only intended for older systems and for use in testing and development systems. 32-bit versions ofMongoDB only support databases smaller than 2GB.

    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 downloadthe correct version of MongoDB for your Windows system. The 64-bit versions of MongoDB does not work with32-bit Windows.

    Step 3: Install the downloaded file.

    In Windows Explorer, locate the downloaded MongoDB msi file, which typically is located in the default Downloadsfolder. 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 thefolder 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 folderyou choose. You may install MongoDB in any folder (e.g. D:\test\mongodb)

    10http://support.microsoft.com/kb/273128411http://www.mongodb.org/downloads

    2.1. Installation Guides 19

  • MongoDB Documentation, Release 2.6.4

    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.

    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"

    Step 2: Start MongoDB.

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

    C:\Program Files\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 block-ing some features of C:\Program Files\MongoDB\bin\mongod.exe from communicating on networks.All users should select Private Networks, such as my home or work network and click Allowaccess. For additional information on security and MongoDB, please see the Security Documentation (page 269).

    Step 3: Connect to MongoDB.

    To connect to MongoDB through the mongo.exe shell, open another Command Prompt. When connecting, specifythe 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:\mongodb\bin\mongo.exe

    If you installation uses a different data directory, specify the directory when connecting, as in this 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"

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

    12http://docs.mongodb.org/ecosystem/drivers/csharp

    20 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    Step 4: Begin using MongoDB.

    To begin using MongoDB, see Getting Started with MongoDB (page 40). Also consider the Production Notes(page 180) 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 instructionsin this section. For MongoDB 2.6.0, use Manually Create a Windows Service for MongoDB (page 22) to create aWindows Service for MongoDB instead.

    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 Files\MongoDB\log"

    In the Command Prompt, create a configuration file for the logpath option for MongoDB:

    echo logpath="C:\Program Files\MongoDB\log\mongo.log" > "C:\Program Files\MongoDB\mongod.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 Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.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:\ProgramFiles\MongoDB\mongod.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 \data\db.

    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 Files\MongoDB\bin\mongod.exe" --remove

    13https://jira.mongodb.org/browse/SERVER-13515

    2.1. Installation Guides 21

  • MongoDB Documentation, Release 2.6.4

    Manually Create a Windows Service for MongoDB

    The following procedure assumes you have installed MongoDB using the MSI installer, with the default pathC:\Program Files\MongoDB 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.

    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:\data\dbmkdir c:\data\log

    Step 3: Create a configuration file.

    Create a configuration file. This file can include any of the configuration options for mongod, butmust include a valid setting for logpath:

    The following creates a configuration file, specifying both the logpath and the dbpath settings in the configurationfile:

    echo logpath=c:\data\log\mongod.log> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"echo dbpath=c:\data\db>> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"

    Step 4: Create the MongoDB service.

    Create the MongoDB service.

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

    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

    22 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    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.4 Install MongoDB Enterprise

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

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

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

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

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

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

    Install MongoDB Enterprise on Windows (page 33) 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. The tutorial uses.rpm packages to install.

    Packages

    MongoDB provides packages of the officially supported MongoDB Enterprise builds in its own repository. Thisrepository 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.

    2.1. Installation Guides 23

  • MongoDB Documentation, Release 2.6.4

    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 599).You can use the mongod init script to derive your own mongos control script.

    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.

    Use the following repository file to specify the latest stable release of MongoDB enterprise.

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

    Use the following repository to install only versions of MongoDB for the 2.6 release. If youd like to install Mon-goDB Enterprise packages from a particular release series (page 794), 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 informationfor 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

    Step 1: 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.

    Install the latest stable version of MongoDB Enterprise. Issue the following command:

    sudo yum install mongodb-enterprise

    Step 2: Optional. Manage Installed Version

    24 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

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

    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 information14.

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

    Run MongoDB Enterprise

    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.

    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/mongo/mongod.log file.

    Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 40). Alsoconsider the Production Notes (page 180) 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. The tutorial uses .deb packages to install.

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

    2.1. Installation Guides 25

  • MongoDB Documentation, Release 2.6.4

    Packages

    MongoDB provides packages of the officially supported MongoDB Enterprise builds in its own repository. Thisrepository 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 599).You can use the mongod init script to derive your own mongos control script.

    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 withGPG keys. Issue the following command to import the MongoDB public GPG Key15:

    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. Createthe list file using the following command:

    echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/stable multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list

    If youd like to install MongoDB Enterprise packages from a particular release series (page 794), 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 releaseseries, add the following repository:

    echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/2.6 multiverse' | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-2.6.list

    15http://docs.mongodb.org/10gen-gpg-key.asc

    26 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    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 installthe 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 theversion 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 mongodb-enterprise-mongos=2.6.1 mongodb-enterprise-tools=2.6.1

    You can specify any available version of MongoDB Enterprise. However apt-get will upgrade the packages whena newer version becomes available. To prevent unintended upgrades, pin the package. To pin the version of MongoDBEnterprise at the currently installed version, issue the following command sequence:

    echo "mongodb-enterprise hold" | sudo dpkg --set-selectionsecho "mongodb-enterprise-server hold" | sudo dpkg --set-selectionsecho "mongodb-enterprise-shell hold" | sudo dpkg --set-selectionsecho "mongodb-enterprise-mongos hold" | sudo dpkg --set-selectionsecho "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-mentation16 for more information.

    Run MongoDB Enterprise

    The MongoDB Enterprise instance stores its data files in /var/lib/mongo and its log files in /var/log/mongo,and runs using the mongod user account. If you change the user that runs the MongoDB process, you must modifythe access control rights to the /var/lib/mongo and /var/log/mongo 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 successfullyby checking the contents of the log file at /var/log/mongodb/mongod.log.

    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

    16http://docs.mongodb.org/v2.4/tutorial/install-mongodb-enterprise

    2.1. Installation Guides 27

  • MongoDB Documentation, Release 2.6.4

    Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 40). Alsoconsider the Production Notes (page 180) 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. The tutorial uses .deb packages to install.

    Packages

    MongoDB provides packages of the officially supported MongoDB Enterprise builds in its own repository. Thisrepository 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 599).You can use the mongod init script to derive your own mongos control script.

    Install MongoDB Enterprise

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

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

    17http://docs.mongodb.org/10gen-gpg-key.asc

    28 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

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

    echo 'deb http://repo.mongodb.com/apt/debian wheezy/mongodb-enterprise/stable main' | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list

    If youd like to install MongoDB Enterprise packages from a particular release series (page 794), such as 2.6, you canspecify 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/sources.list.d/mongodb-enterprise-2.6.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 Enterprise packages. When you install the packages, you choose whether to installthe 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 theversion 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 mongodb-enterprise-mongos=2.6.1 mongodb-enterprise-tools=2.6.1

    You can specify any available version of MongoDB Enterprise. However apt-get will upgrade the packages whena newer version becomes available. To prevent unintended upgrades, pin the package. To pin the version of MongoDBEnterprise at the currently installed version, issue the following command sequence:

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

    Run MongoDB Enterprise

    The MongoDB Enterprise instance stores its data files in /var/lib/mongo and its log files in /var/log/mongo,and runs using the mongod user account. If you change the user that runs the MongoDB process, you must modifythe access control rights to the /var/lib/mongo and /var/log/mongo 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 successfullyby checking the contents of the log file at /var/log/mongodb/mongod.log.

    2.1. Installation Guides 29

  • MongoDB Documentation, Release 2.6.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. 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 40). Alsoconsider the Production Notes (page 180) 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 platformsand 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

    Install MongoDB Enterprise

    Note: The Enterprise packages include an example SNMP configuration file named mongod.conf. This file is nota 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 packagesfrom http://www.mongodb.com/subscription/downloads. The MongoDB binaries are located in thehttp://docs.mongodb.org/manualbin directory of the archive. To download and install, use thefollowing sequence of commands.

    curl -O http://downloads.10gen.com/linux/mongodb-linux-x86_64-subscription-suse11-2.6.3.tgztar -zxvf mongodb-linux-x86_64-subscription-suse11-2.6.3.tgzcp -R -n mongodb-linux-x86_64-subscription-suse11-2.6.3/ mongodb

    30 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    Step 2: Ensure the location of the MongoDB binaries is included in the PATH variable. Once you have copiedthe 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 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: Stop MongoDB as needed. To stop MongoDB, press Control+C in the terminal where the mongodinstance is running.

    Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 40). Alsoconsider the Production Notes (page 180) 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 selectplatforms and contains support for several features related to security and monitoring.

    2.1. Installation Guides 31

  • MongoDB Documentation, Release 2.6.4

    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 cyrus-sasl-gssapi

    Install MongoDB Enterprise

    Note: The Enterprise packages include an example SNMP configuration file named mongod.conf. This file is nota 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 packagesfrom http://www.mongodb.com/subscription/downloads. The MongoDB binaries are located in thehttp://docs.mongodb.org/manualbin directory of the archive. To download and install, use thefollowing sequence of commands.

    curl -O http://downloads.10gen.com/linux/mongodb-linux-x86_64-subscription-amzn64-2.6.3.tgztar -zxvf mongodb-linux-x86_64-subscription-amzn64-2.6.3.tgzcp -R -n mongodb-linux-x86_64-subscription-amzn64-2.6.3/ mongodb

    Step 2: Ensure the location of the MongoDB binaries is included in the PATH variable. Once you have copiedthe 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 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

    32 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    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: Stop MongoDB as needed. To stop MongoDB, press Control+C in the terminal where the mongodinstance is running.

    Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 40). Alsoconsider the Production Notes (page 180) 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 selectplatforms 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 allother software dependencies.

    Install MongoDB Enterprise

    Step 1: Download MongoDB Enterprise for Windows. Download the latest production release of MongoDBEnterprise18

    18http://www.mongodb.com/products/mongodb-enterprise

    2.1. Installation Guides 33

  • MongoDB Documentation, Release 2.6.4

    Step 2: Install MongoDB Enterprise for Windows. Run the downloaded MSI installer. Make configurationchoices as prompted.

    MongoDB is self-contained and does not have any other system dependencies. You can install MongoDB into anyfolder (e.g. D:\test\mongodb) and run it from there. The installation wizard includes an option to select aninstallation directory.

    Run MongoDB Enterprise

    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.

    Step 1: Set up the MongoDB environment. MongoDB requires a data directory to store all data. MongoDBsdefault data directory path is \data\db. Create this 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"

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

    C:\Program Files\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 block-ing some features of C:\Program Files\MongoDB\bin\mongod.exe from communicating on networks.All users should select Private Networks, such as my home or work network and click Allowaccess. For additional information on security and MongoDB, please see the Security Documentation (page 269).

    Step 3: Connect to MongoDB. To connect to MongoDB through the mongo.exe shell, open another CommandPrompt. When connecting, specify the data directory if necessary. This step provides several example connectioncommands.

    If your MongoDB installation uses the default data directory, connect without specifying the data directory:

    C:\mongodb\bin\mongo.exe

    If you installation uses a different data directory, specify the directory when connecting, as in this 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"

    34 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

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

    Step 4: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 40). Alsoconsider the Production Notes (page 180) 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 logoutput (logpath):

    Create a specific directory for MongoDB log files:

    md "C:\Program Files\MongoDB\log"

    In the Command Prompt, create a configuration file for the logpath option for MongoDB:

    echo logpath="C:\Program Files\MongoDB\log\mongo.log" > "C:\Program Files\MongoDB\mongod.cfg"

    Step 2: Run the MongoDB service. Run all of the following commands in Command Prompt with AdministrativePrivileges:

    Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option.

    "C:\Program Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.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:\ProgramFiles\MongoDB\mongod.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 \data\db.

    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 Files\MongoDB\bin\mongod.exe" --remove

    Configure a Windows Service for MongoDB Enterprise

    Note: There is a known issue for MongoDB 2.6.0, SERVER-1351520, which prevents the use of the instructionsin this section. For MongoDB 2.6.0, use Manually Create a Windows Service for MongoDB Enterprise (page 36) tocreate a Windows Service for MongoDB.

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

    19http://docs.mongodb.org/ecosystem/drivers/csharp20https://jira.mongodb.org/browse/SERVER-13515

    2.1. Installation Guides 35

  • MongoDB Documentation, Release 2.6.4

    Step 1: Configure directories and files. Create a configuration file and a directory path for MongoDB logoutput (logpath):

    Create a specific directory for MongoDB log files:

    md "C:\Program Files\MongoDB\log"

    In the Command Prompt, create a configuration file for the logpath option for MongoDB:

    echo logpath="C:\Program Files\MongoDB\log\mongo.log" > "C:\Program Files\MongoDB\mongod.cfg"

    Step 2: Run the MongoDB service. Run all of the following commands in Command Prompt with AdministrativePrivileges:

    Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option.

    "C:\Program Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.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:\ProgramFiles\MongoDB\mongod.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 \data\db.

    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 Files\MongoDB\bin\mongod.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 pathC:\Program Files\MongoDB 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:\data\dbmkdir c:\data\log

    36 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    Step 3: Create a configuration file. Create a configuration file. This file can include any of theconfiguration 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 configurationfile:

    echo logpath=c:\data\log\mongod.log> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"echo dbpath=c:\data\db>> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"

    Step 4: Create the MongoDB service. Create the MongoDB service.

    sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Enterprise\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Standard\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"

    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 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 avalid and unaltered MongoDB release.

    Before installing MongoDB, you can validate packages using either a PGP signature or with MD5 and SHA checksumsof the MongoDB packages. The PGP signatures store an encrypted hash of the software package, that you can validateto ensure that the package you have is consistent with the official package release. MongoDB also publishes MD5 andSHA 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 areavailable at the following URLs:

    https://www.mongodb.org/static/pgp/server-2.2.aschttps://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 MongoDBreleases beginning with 2.2.

    2.1. Installation Guides 37

  • MongoDB Documentation, Release 2.6.4

    Procedures

    Use PGP/GPG

    Step 1: Download the MongoDB installation file. Download the binaries fromhttps://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 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 thesecommands:

    curl -LO https://www.mongodb.org/static/pgp/server-2.6.ascgpg --import server-2.6.asc

    You should receive this message:

    gpg: key AAB2461C: public key "MongoDB 2.6 Release Signing Key " importedgpg: Total number processed: 1gpg: 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 AAB2461Cgpg: Good signature from "MongoDB 2.6 Release Signing Key "

    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 AAB2461Cgpg: 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 keyin 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.

    38 Chapter 2. Install MongoDB

  • MongoDB Documentation, Release 2.6.4

    Step 1: Download the MongoDB installation file. Download the binaries fromhttps://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.sha1curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.3.tgz.sha256

    Step 3: Use the SHA-256 checksum to verify the MongoDB package file. Compute the checksum of the packagefile:

    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 packagefile:

    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 fromhttps://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:

    2.1. Installation Guides 39

  • MongoDB Documentation, Release 2.6.4

    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:

    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