Mongo db manual

837
MongoDB Documentation Release 2.6.4 MongoDB Documentation Project September 16, 2014

description

MongoDB Documentation Release 2.6.4 MongoDB Documentation Project

Transcript of Mongo db manual

  • 1. MongoDB DocumentationRelease 2.6.4MongoDB Documentation ProjectSeptember 16, 2014

2. 2 3. Contents1 Introduction to MongoDB 31.1 What is MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Install MongoDB 52.1 Installation Guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.2 First Steps with MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 433 MongoDB CRUD Operations 513.1 MongoDB CRUD Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 513.2 MongoDB CRUD Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 533.3 MongoDB CRUD Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 843.4 MongoDB CRUD Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1174 Data Models 1314.1 Data Modeling Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1314.2 Data Modeling Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1334.3 Data Model Examples and Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1404.4 Data Model Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1585 Administration 1715.1 Administration Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1715.2 Administration Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2055.3 Administration Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2666 Security 2796.1 Security Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2796.2 Security Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2816.3 Security Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2946.4 Security Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3607 Aggregation 3877.1 Aggregation Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3877.2 Aggregation Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3917.3 Aggregation Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4037.4 Aggregation Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4198 Indexes 4318.1 Index Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4318.2 Index Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 436i 4. 8.3 Indexing Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4648.4 Indexing Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5009 Replication 5039.1 Replication Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5039.2 Replication Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5079.3 Replica Set Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5439.4 Replication Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59310 Sharding 60710.1 Sharding Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60710.2 Sharding Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61310.3 Sharded Cluster Tutorials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63410.4 Sharding Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67811 Frequently Asked Questions 68711.1 FAQ: MongoDB Fundamentals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68711.2 FAQ: MongoDB for Application Developers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69011.3 FAQ: The mongo Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70011.4 FAQ: Concurrency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70211.5 FAQ: Sharding with MongoDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70611.6 FAQ: Replication and Replica Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71111.7 FAQ: MongoDB Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71411.8 FAQ: Indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71811.9 FAQ: MongoDB Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72012 Release Notes 72512.1 Current Stable Release . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72512.2 Previous Stable Releases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76212.3 Other MongoDB Release Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80812.4 MongoDB Version Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80813 About MongoDB Documentation 81113.1 License . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81113.2 Editions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81113.3 Version and Revisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81213.4 Report an Issue or Make a Change Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81213.5 Contribute to the Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 812Index 829ii 5. MongoDB Documentation, Release 2.6.4See About MongoDB Documentation (page 811) for more information about the MongoDB Documentation project,this Manual and additional editions of this text.Note: This version of the PDF does not include the reference section, see MongoDB Reference Manual1 for a PDFedition of all MongoDB Reference Material.1http://docs.mongodb.org/master/MongoDB-reference-manual.pdfContents 1 6. MongoDB Documentation, Release 2.6.42 Contents 7. CHAPTER 1Introduction to MongoDBWelcome 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 MongoDBMongoDB is an open-source document database that provides high performance, high availability, and automaticscaling.1.1.1 Document DatabaseA record in MongoDB is a document, which is a data structure composed of field and value pairs. MongoDB docu-mentsare similar to JSON objects. The values of fields may include other documents, arrays, and arrays of documents.Figure 1.1: A MongoDB document.The advantages of using documents are: Documents (i.e. objects) correspond to native data types in many programming languages. Embedded documents and arrays reduce need for expensive joins. Dynamic schema supports fluent polymorphism.3 8. MongoDB Documentation, Release 2.6.41.1.2 Key FeaturesHigh PerformanceMongoDB 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 AvailabilityTo provide high availability, MongoDBs replication facility, called replica sets, provide: automatic failover. data redundancy.A replica set (page 503) is a group of MongoDB servers that maintain the same data set, providing redundancy andincreasing data availability.Automatic ScalingMongoDB provides horizontal scalability as part of its core functionality. Automatic sharding (page 607) distributes data across a cluster of machines. Replica sets can provide eventually-consistent reads for low-latency high throughput deployments.4 Chapter 1. Introduction to MongoDB 9. CHAPTER 2Install MongoDBMongoDB runs on most platforms and supports both 32-bit and 64-bit architectures.2.1 Installation GuidesSee the Release Notes (page 725) for information about specific releases of MongoDB.Install on Linux (page 6) Documentations for installing the official MongoDB distribution on Linux-based systems.Install on Red Hat (page 6) Install MongoDB on Red Hat Enterprise, CentOS, Fedora and related Linux sys-temsusing .rpm packages.Install on Ubuntu (page 9) Install MongoDB on Ubuntu Linux systems using .deb packages.Install on Debian (page 12) Install MongoDB on Debian systems using .deb packages.Install on Other Linux Systems (page 14) Install the official build of MongoDB on other Linux systems 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 19) Install MongoDB on Windows systems and optionally start MongoDB as a Windowsservice.Install MongoDB Enterprise (page 24) 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 24) Install the MongoDB Enterprise build and required depen-dencieson Red Hat Enterprise or CentOS Systems using packages.Install MongoDB Enterprise on Ubuntu (page 27) Install the MongoDB Enterprise build and required depen-dencieson Ubuntu Linux Systems using packages.Install MongoDB Enterprise on Debian (page 30) Install the MongoDB Enterprise build and required depen-dencieson Debian Linux Systems using packages.Install MongoDB Enterprise on SUSE (page 32) Install the MongoDB Enterprise build and required depen-dencieson SUSE Enterprise Linux.Install MongoDB Enterprise on Amazon AMI (page 34) Install the MongoDB Enterprise build and requireddependencies on Amazon Linux AMI.Install MongoDB Enterprise on Windows (page 36) Install the MongoDB Enterprise build and required de-pendenciesusing the .msi installer.5 10. MongoDB Documentation, Release 2.6.42.1.1 Install on LinuxThese documents provide instructions to install MongoDB for various Linux systems.RecommendedFor 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 12) Install MongoDB on Debian systems using .deb packages.For systems without supported packages, refer to the Manual Installation tutorial.Manual InstallationAlthough packages are the preferred installation method, for Linux systems without supported packages, see thefollowing guide:Install on Other Linux Systems (page 14) Install the official build of MongoDB on other Linux systems from Mon-goDBarchives.Install MongoDB on Red Hat Enterprise, CentOS, Fedora, or Amazon LinuxOverview Use this tutorial to install MongoDB on Red Hat Enterprise Linux, CentOS Linux, Fedora Linux, or arelated system from .rpm packages. While some of these distributions include their own MongoDB packages, theofficial 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-orgThis package is a metapackage that will automatically install the four component packages listed below. mongodb-org-serverThis package contains the mongod daemon and associated configuration and init scripts. mongodb-org-mongosThis package contains the mongos daemon. mongodb-org-shellThis package contains the mongo shell. mongodb-org-toolsThis package contains the following MongoDB tools: mongoimport bsondump, mongodump,mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,mongostat, and mongotop.6 Chapter 2. Install MongoDB 11. MongoDB Documentation, Release 2.6.4Control 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. 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 613).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.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; seeSERVER-7285a for more information. In the mean time use your own control scripts or install using the procedureoutlined in Install MongoDB on Linux Systems (page 14).ahttps://jira.mongodb.org/browse/SERVER-7285Considerations For production deployments, always run MongoDB on 64-bit systems.The default /etc/mongodb.conf configuration file supplied by the 2.6 series packages has bind_ip set 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-lationof an older release, please refer to the documentation for the appropriate version.Install MongoDBStep 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=1If 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=1Step 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-org2.1. Installation Guides 7 12. MongoDB Documentation, Release 2.6.4To 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 -y mongodb-org-2.6.1 mongodb-org-server-2.6.1 mongodb-org-shell-2.6.1 mongodb-org-mongos-You can specify any available version of MongoDB. However yum will upgrade the packages when a newer 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-toolsPrevious 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 Red Hat Linux-based systems (Red HatEnterprise Linux, CentOS, Fedora). Administrators have three options: enable access to the relevant ports (e.g. 27017) for SELinux. See Default MongoDB Port (page 380) for moreinformation on MongoDBs default ports. For default settings, this can be accomplished by runningsemanage port -a -t mongodb_port_t -p tcp 27017 set SELinux to permissive mode in /etc/selinux.conf. The lineSELINUX=enforcingshould be changed toSELINUX=permissive disable SELinux entirely; as above but setSELINUX=disabledAll three options require root privileges. The latter two options each requires a system reboot and may have largerimplications for your deployment.You may alternatively choose not to install the SELinux packages when you are installing your Linux operating system,or choose to remove the relevant packages. This option is the most invasive and is not recommended.The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodbby default, and runs using the mongod user account. You can specify alternate log and data file directories in/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.If you change the user that runs the MongoDB process, you must modify the access control rights to the/var/lib/mongo and /var/log/mongodb directories to give this users access to these directories.Step 1: Start MongoDB. You can start the mongod process by issuing the following command:sudo service mongod startStep 2: Verify that MongoDB has started successfully You can verify that the mongod process has started suc-cessfullyby checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading1http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-linux8 Chapter 2. Install MongoDB 13. MongoDB Documentation, Release 2.6.4[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 onStep 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:sudo service mongod stopStep 4: Restart MongoDB. You can restart the mongod process by issuing the following command:sudo service mongod restartYou can follow the state of the process for errors or important messages by watching the output in the/var/log/mongodb/mongod.log file.Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.Install MongoDB on UbuntuOverview Use this tutorial to install MongoDB on Ubuntu Linux systems from .deb packages. While Ubuntuincludes its own MongoDB packages, the official MongoDB packages are generally more up-to-date.Note: If you use an older Ubuntu that does not use Upstart (i.e. any version before 9.10 Karmic), please follow theinstructions on the Install MongoDB on Debian (page 12) 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-orgThis package is a metapackage that will automatically install the four component packages listed below. mongodb-org-serverThis package contains the mongod daemon and associated configuration and init scripts. mongodb-org-mongosThis package contains the mongos daemon. mongodb-org-shellThis package contains the mongo shell. mongodb-org-toolsThis package contains the following MongoDB tools: mongoimport bsondump, mongodump,mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,mongostat, and mongotop.2.1. Installation Guides 9 14. MongoDB Documentation, Release 2.6.4Control 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. 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 613).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 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-agesprovided by Ubuntu.The default /etc/mongodb.conf configuration file supplied by the 2.6 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-lationof an older release, please refer to the documentation for the appropriate version.Install MongoDBStep 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 7F0CEB10Step 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.Step 3: Reload local package database. Issue the following command to reload the local package database:sudo apt-get updateStep 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-orgInstall a specific release of MongoDB. Specify each component package individually and append the version num-berto the package name, as in the following example that installs the 2.6.1 release of MongoDB:2http://docs.mongodb.org/10gen-gpg-key.asc10 Chapter 2. Install MongoDB 15. MongoDB Documentation, Release 2.6.4sudo apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-Pin a specific version of MongoDB. Although you can specify any available version of MongoDB, apt-get 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-selectionsPrevious 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 by default, and runs using the mongodb user account. You can specify alternate log anddata file directories in /etc/mongodb.conf. See systemLog.path and storage.dbPath for additionalinformation.If you change the user that runs the MongoDB process, you must modify the access control rights to the/var/lib/mongodb and /var/log/mongodb directories to give this users access to these directories.Step 1: Start MongoDB. Issue the following command to start mongod:sudo service mongod startStep 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 stopStep 4: Restart MongoDB. Issue the following command to restart mongod:sudo service mongod restartStep 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.3http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-ubuntu2.1. Installation Guides 11 16. MongoDB Documentation, Release 2.6.4Install MongoDB on DebianOverview Use this tutorial to install MongoDB on Debian systems from .deb packages. While some Debiandistributions include their own MongoDB packages, the official MongoDB packages are generally more up to date.Note: This tutorial applies to both Debian systems and versions of Ubuntu Linux prior to 9.10 Karmic which 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-orgThis package is a metapackage that will automatically install the four component packages listed below. mongodb-org-serverThis package contains the mongod daemon and associated configuration and init scripts. mongodb-org-mongosThis package contains the mongos daemon. mongodb-org-shellThis package contains the mongo shell. mongodb-org-toolsThis package contains the following MongoDB tools: mongoimport bsondump, mongodump,mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,mongostat, and mongotop.Control Scripts The mongodb-org package includes various control scripts, including the init script/etc/init.d/mongod. These scripts are used to stop, start, and restart daemon processes.The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts. 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 613).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 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-agesthat your release of Debian may include.The default /etc/mongodb.conf configuration file supplied by the 2.6 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-lationof 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.12 Chapter 2. Install MongoDB 17. MongoDB Documentation, Release 2.6.4Step 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 7F0CEB10Step 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.Step 3: Reload local package database. Issue the following command to reload the local package database:sudo apt-get updateStep 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-orgInstall a specific release of MongoDB. Specify each component package individually and append the version num-berto the package name, as in the following example that installs the 2.6.1 release of MongoDB:sudo apt-get install -y mongodb-org=2.6.1 mongodb-org-server=2.6.1 mongodb-org-shell=2.6.1 mongodb-org-Pin a specific version of MongoDB. Although you can specify any available version of MongoDB, apt-get 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-selectionsPrevious 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/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/mongodb.conf. See systemLog.path and storage.dbPath for additionalinformation.If you change the user that runs the MongoDB process, you must modify the access control rights to the/var/lib/mongodb and /var/log/mongodb directories to give this users access to these directories.4http://docs.mongodb.org/10gen-gpg-key.asc5http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-ubuntu2.1. Installation Guides 13 18. MongoDB Documentation, Release 2.6.4Step 1: Start MongoDB. Issue the following command to start mongod:sudo service mongod startStep 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 stopStep 4: Restart MongoDB. Issue the following command to restart mongod:sudo service mongod restartStep 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.Install MongoDB on Linux SystemsOverview 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 LinuxStep 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.4.tgzStep 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.4.tgz14 Chapter 2. Install MongoDB 19. MongoDB Documentation, Release 2.6.4Step 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.4/ mongodbStep 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:$PATHReplace with the path to the extracted MongoDB archive.Install for 32-bit LinuxStep 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.4.tgzStep 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.4.tgzStep 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.4/ mongodbStep 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:$PATHReplace with the path to the extracted MongoDB archive.Run MongoDBStep 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:2.1. Installation Guides 15 20. MongoDB Documentation, Release 2.6.4mkdir -p /data/dbStep 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:mongodSpecify 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:/mongodSpecify 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 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.2.1.2 Install MongoDB on OS XOverviewUse 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 MongoDBYou can install MongoDB with Homebrew8 or manually. This section describes both.6http://brew.sh/7http://www.mongodb.org/downloads8http://brew.sh/16 Chapter 2. Install MongoDB 21. MongoDB Documentation, Release 2.6.4Install MongoDB with HomebrewHomebrew9 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 updateStep 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 mongodbBuild 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-opensslInstall 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 --develInstall MongoDB ManuallyOnly install MongoDB using this procedure if you cannot use homebrew (page 17).Step 1: Download the binary files for the desired release of MongoDB.Download the binaries from https://www.mongodb.org/downloads.For example, to download the latest release through the shell, issue the following:curl -O http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.4.tgzStep 2: Extract the files from the downloaded archive.For example, from a system shell, you can extract through the tar command:9http://brew.sh/2.1. Installation Guides 17 22. MongoDB Documentation, Release 2.6.4tar -zxvf mongodb-osx-x86_64-2.6.4.tgzStep 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.4/ mongodbStep 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:$PATHReplace with the path to the extracted MongoDB archive.Run MongoDBStep 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:mkdir -p /data/dbStep 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-sionsfor 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:mongod18 Chapter 2. Install MongoDB 23. MongoDB Documentation, Release 2.6.4Specify 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:/mongodSpecify 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 43). Also consider the Production Notes(page 188) document before deploying MongoDB in a production environment.2.1.3 Install MongoDB on WindowsOverviewUse 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.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 MongoDBStep 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 forWindows 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.10http://support.microsoft.com/kb/27312842.1. Installation Guides 19 24. MongoDB Documentation, Release 2.6.4To find which version of Windows you are running, enter the following command in the Command Prompt:wmic os get osarchitectureStep 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.InWindows 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:mongodbMongoDB 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:testmongodb)Run MongoDBWarning: 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 datadb. Createthis folder using the following commands from a Command Prompt:md datadbYou can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:C:mongodbbinmongod.exe --dbpath d:testmongodbdataIf your path includes spaces, enclose the entire path in double quotes, for example:11http://www.mongodb.org/downloads20 Chapter 2. Install MongoDB 25. MongoDB Documentation, Release 2.6.4C:mongodbbinmongod.exe --dbpath "d:testmongo db data"Step 2: Start MongoDB.To start MongoDB, run mongod.exe. For example, from the Command Prompt:C:Program FilesMongoDBbinmongod.exeThis 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-ingsome features of C:Program FilesMongoDBbinmongod.exe from communicating on networks.All users should select Private Networks, such as my home or work network and click Allowaccess. For additional information on security and MongoDB, please see the Security Documentation (page 281).Step 3: Connect to MongoDB.To connect to MongoDB through the mongo.exe shell, open another Command Prompt. When connecting, 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:mongodbbinmongo.exeIf you installation uses a different data directory, specify the directory when connecting, as in this example:C:mongodbbinmongod.exe --dbpath d:testmongodbdataIf your path includes spaces, enclose the entire path in double quotes. For example:C:mongodbbinmongod.exe --dbpath "d:testmongo db data"If you want to develop applications using .NET, see the documentation of C# and MongoDB12 for more information.Step 4: Begin using MongoDB.To begin using MongoDB, see Getting Started with MongoDB (page 43). Also consider the Production Notes(page 188) document before deploying MongoDB in a production environment.Configure a Windows Service for MongoDBNote: 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.12http://docs.mongodb.org/ecosystem/drivers/csharp13https://jira.mongodb.org/browse/SERVER-135152.1. Installation Guides 21 26. MongoDB Documentation, Release 2.6.4Step 1: Configure directories and files.Create a configuration file and a directory path for MongoDB log output (logpath):Create a specific directory for MongoDB log files:md "C:Program FilesMongoDBlog"In the Command Prompt, create a configuration file for the logpath option for MongoDB:echo logpath="C:Program FilesMongoDBlogmongo.log" > "C:Program FilesMongoDBmongod.cfg"Step 2: Run the MongoDB service.Run all of the following commands in Command Prompt with Administrative Privileges:Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option."C:Program FilesMongoDBbinmongod.exe" --config "C:Program FilesMongoDBmongod.cfg" --installModify the path to the mongod.cfg file as needed.To use an alternate dbpath, specify the path in the configuration file (e.g. C:ProgramFilesMongoDBmongod.cfg) or on the command line with the --dbpath option.If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is datadb.If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service witha unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient systemresources exist and your system design requires it.Step 3: Stop or remove the MongoDB service as needed.To stop the MongoDB service use the following command:net stop MongoDBTo remove the MongoDB service use the following command:"C:Program FilesMongoDBbinmongod.exe" --removeManually Create a Windows Service for MongoDBThe following procedure assumes you have installed MongoDB using the MSI installer, with the default pathC:Program FilesMongoDB 2.6 Standard.If you have installed in an alternative directory, you will need to adjust the paths as appropriate.Step 1: Open an Administrator command prompt.Windows 7 / Vista / Server 2008 (and R2) Press Win + R, then type cmd, then press Ctrl + Shift +Enter.22 Chapter 2. Install MongoDB 27. MongoDB Documentation, Release 2.6.4Windows 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:datadbmkdir c:datalogStep 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:datalogmongod.log> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"echo dbpath=c:datadb>> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"Step 4: Create the MongoDB service.Create the MongoDB service.sc.exe create MongoDB binPath= ""C:Program FilesMongoDB 2.6 Standardbinmongod.exe" --service --sc.exe requires a space between = and the configuration values (eg binPath= ), and a to escape double quotes.If successfully created, the following log message will display:[SC] CreateService SUCCESSStep 5: Start the MongoDB service.net start MongoDBStep 6: Stop or remove the MongoDB service as needed.To stop the MongoDB service, use the following command:net stop MongoDBTo remove the MongoDB service, first stop the service and then run the following command:sc.exe delete MongoDB2.1. Installation Guides 23 28. MongoDB Documentation, Release 2.6.42.1.4 Install MongoDB EnterpriseThese documents provide instructions to install MongoDB Enterprise for Linux and Windows Systems.Install MongoDB Enterprise on Red Hat (page 24) Install the MongoDB Enterprise build and required dependen-cieson Red Hat Enterprise or CentOS Systems using packages.Install MongoDB Enterprise on Ubuntu (page 27) Install the MongoDB Enterprise build and required dependencieson Ubuntu Linux Systems using packages.Install MongoDB Enterprise on Debian (page 30) Install the MongoDB Enterprise build and required dependencieson Debian Linux Systems using packages.Install MongoDB Enterprise on SUSE (page 32) Install the MongoDB Enterprise build and required dependencieson SUSE Enterprise Linux.Install MongoDB Enterprise on Amazon AMI (page 34) Install the MongoDB Enterprise build and required depen-dencieson Amazon Linux AMI.Install MongoDB Enterprise on Windows (page 36) Install the MongoDB Enterprise build and required dependen-ciesusing the .msi installer.Install MongoDB Enterprise on Red Hat Enterprise or CentOSOverviewUse this tutorial to install MongoDB Enterprise on Red Hat Enterprise Linux or CentOS Linux from .rpm packages.PackagesMongoDB provides packages of the officially supported MongoDB Enterprise builds in its own repository. Thisrepository provides the MongoDB Enterprise distribution in the following packages: mongodb-enterpriseThis package is a metapackage that will automatically install the four component packages listed below. mongodb-enterprise-serverThis package contains the mongod daemon and associated configuration and init scripts. mongodb-enterprise-mongosThis package contains the mongos daemon. mongodb-enterprise-shellThis package contains the mongo shell. mongodb-enterprise-toolsThis package contains the following MongoDB tools: mongoimport bsondump, mongodump,mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,mongostat, and mongotop.24 Chapter 2. Install MongoDB 29. MongoDB Documentation, Release 2.6.4Control ScriptsThe mongodb-enterprise package includes various control scripts, including the init script/etc/rc.d/init.d/mongod.The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts.As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).You can use the mongod init script to derive your own mongos control script.ConsiderationsMongoDB only provides Enterprise packages for Red Hat Enterprise Linux and CentOS Linux versions 5 and 6,64-bit.The default /etc/mongodb.conf configuration file supplied by the 2.6 series packages has bind_ip set 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-lationof an older release, please refer to the documentation for the appropriate version.Install MongoDB EnterpriseWhen 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=1Use the following repository to install only versions of MongoDB for the 2.6 release. If youd like to install Mon-goDBEnterprise packages from a particular release series (page 808), such as 2.4 or 2.6, you can specify the re-leaseseries 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.repo files for each release can also be found in the repository itself14. Remember that odd-numbered minor releaseversions (e.g. 2.5) are development versions and are unsuitable for production deployment.Step 1: Install the MongoDB Enterprise packages and associated tools. You can install either the latest stableversion of MongoDB Enterprise or a specific version of MongoDB Enterprise.14https://repo.mongodb.com/yum/redhat/2.1. Installation Guides 25 30. MongoDB Documentation, Release 2.6.4Install the latest stable version of MongoDB Enterprise. Issue the following command:sudo yum install -y mongodb-enterpriseStep 2: Optional. Manage Installed VersionInstall 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-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,Previous versions of MongoDB packages use different naming conventions. See the 2.4 version of documentation formore information15.Step 3: When the install completes, you can run MongoDB.Run MongoDB EnterpriseImportant: You must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red HatEnterprise Linux, CentOS, Fedora). Administrators have three options: enable access to the relevant ports (e.g. 27017) for SELinux. See Default MongoDB Port (page 380) for moreinformation on MongoDBs default ports. For default settings, this can be accomplished by runningsemanage port -a -t mongodb_port_t -p tcp 27017 set SELinux to permissive mode in /etc/selinux.conf. The lineSELINUX=enforcingshould be changed toSELINUX=permissive disable SELinux entirely; as above but setSELINUX=disabledAll three options require root privileges. The latter two options each requires a system reboot and may have largerimplications for your deployment.You may alternatively choose not to install the SELinux packages when you are installing your Linux operating system,or choose to remove the relevant packages. This option is the most invasive and is not recommended.The MongoDB instance stores its data files in /var/lib/mongo and its log files in /var/log/mongodbby default, and runs using the mongod user account. You can specify alternate log and data file directories in/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.15http://docs.mongodb.org/v2.4/tutorial/install-mongodb-on-linux26 Chapter 2. Install MongoDB 31. MongoDB Documentation, Release 2.6.4If you change the user that runs the MongoDB process, you must modify the access control rights to the/var/lib/mongo and /var/log/mongodb directories to give this users access to these directories.Step 1: Start MongoDB. You can start the mongod process by issuing the following command:sudo service mongod startStep 2: Verify that MongoDB has started successfully You can verify that the mongod process has started suc-cessfullyby 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 onStep 3: Stop MongoDB. As needed, you can stop the mongod process by issuing the following command:sudo service mongod stopStep 4: Restart MongoDB. You can restart the mongod process by issuing the following command:sudo service mongod restartYou can follow the state of the process for errors or important messages by watching the output in the/var/log/mongodb/mongod.log file.Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.Install MongoDB Enterprise on UbuntuOverviewUse this tutorial to install MongoDB Enterprise on Ubuntu Linux systems from .deb packages.PackagesMongoDB provides packages of the officially supported MongoDB Enterprise builds in its own repository. Thisrepository provides the MongoDB Enterprise distribution in the following packages: mongodb-enterpriseThis package is a metapackage that will automatically install the four component packages listed below. mongodb-enterprise-serverThis package contains the mongod daemon and associated configuration and init scripts. mongodb-enterprise-mongosThis package contains the mongos daemon.2.1. Installation Guides 27 32. MongoDB Documentation, Release 2.6.4 mongodb-enterprise-shellThis package contains the mongo shell. mongodb-enterprise-toolsThis package contains the following MongoDB tools: mongoimport bsondump, mongodump,mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,mongostat, and mongotop.Control ScriptsThe mongodb-enterprise package includes various control scripts, including the init script/etc/rc.d/init.d/mongod.The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts.As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).You can use the mongod init script to derive your own mongos control script.ConsiderationsMongoDB only provides Enterprise packages for Ubuntu 12.04 LTS (Precise Pangolin).Changed in version 2.6: The package structure and names have changed as of version 2.6. For instructions on instal-lationof an older release, please refer to the documentation for the appropriate version.Install MongoDB EnterpriseStep 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 Key16:sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10Step 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 If youd like to install MongoDB Enterprise packages from a particular release series (page 808), such as 2.4 or 2.6,you can specify the release series in the repository configuration. For example, to restrict your system to the 2.6 releaseseries, add the following repository:echo 'deb http://repo.mongodb.com/apt/ubuntu precise/mongodb-enterprise/2.6 multiverse' | sudo tee /etc/Step 3: Reload local package database. Issue the following command to reload the local package database:sudo apt-get update16http://docs.mongodb.org/10gen-gpg-key.asc28 Chapter 2. Install MongoDB 33. MongoDB Documentation, Release 2.6.4Step 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-enterpriseTo 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 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-selectionsPrevious versions of MongoDB Enterprise packages use different naming conventions. See the 2.4 version of docu-mentation17for more information.Run MongoDB EnterpriseThe MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodbby default, and runs using the mongodb user account. You can specify alternate log and data file directories in/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.If you change the user that runs the MongoDB process, you must modify the access control rights to the/var/lib/mongodb and /var/log/mongodb directories to give this users access to these directories.Step 1: Start MongoDB. Issue the following command to start mongod:sudo service mongod startStep 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 stopStep 4: Restart MongoDB. Issue the following command to restart mongod:17http://docs.mongodb.org/v2.4/tutorial/install-mongodb-enterprise2.1. Installation Guides 29 34. MongoDB Documentation, Release 2.6.4sudo service mongod restartStep 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.Install MongoDB Enterprise on DebianOverviewUse this tutorial to install MongoDB Enterprise on Debian Linux systems from .deb packages.PackagesMongoDB provides packages of the officially supported MongoDB Enterprise builds in its own repository. Thisrepository provides the MongoDB Enterprise distribution in the following packages: mongodb-enterpriseThis package is a metapackage that will automatically install the four component packages listed below. mongodb-enterprise-serverThis package contains the mongod daemon and associated configuration and init scripts. mongodb-enterprise-mongosThis package contains the mongos daemon. mongodb-enterprise-shellThis package contains the mongo shell. mongodb-enterprise-toolsThis package contains the following MongoDB tools: mongoimport bsondump, mongodump,mongoexport, mongofiles, mongoimport, mongooplog, mongoperf, mongorestore,mongostat, and mongotop.Control ScriptsThe mongodb-enterprise package includes various control scripts, including the init script/etc/rc.d/init.d/mongod.The package configures MongoDB using the /etc/mongod.conf file in conjunction with the control scripts.As of version 2.6.4, there are no control scripts for mongos. The mongos process is used only in sharding (page 613).You can use the mongod init script to derive your own mongos control script.ConsiderationsChanged in version 2.6: The package structure and names have changed as of version 2.6. For instructions on instal-lationof an older release, please refer to the documentation for the appropriate version.MongoDB only provides Enterprise packages for 64-bit versions of Debian Wheezy.30 Chapter 2. Install MongoDB 35. MongoDB Documentation, Release 2.6.4Install MongoDB EnterpriseStep 1: Import the public key used by the package management system. Issue the following command to addthe MongoDB public GPG Key18 to the system key ring.sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10Step 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/If youd like to install MongoDB Enterprise packages from a particular release series (page 808), 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/Step 3: Reload local package database. Issue the following command to reload the local package database:sudo apt-get updateStep 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-enterpriseTo 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 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-selectionsRun MongoDB EnterpriseThe MongoDB instance stores its data files in /var/lib/mongodb and its log files in /var/log/mongodbby default, and runs using the mongodb user account. You can specify alternate log and data file directories in/etc/mongodb.conf. See systemLog.path and storage.dbPath for additional information.If you change the user that runs the MongoDB process, you must modify the access control rights to the/var/lib/mongodb and /var/log/mongodb directories to give this users access to these directories.18http://docs.mongodb.org/10gen-gpg-key.asc2.1. Installation Guides 31 36. MongoDB Documentation, Release 2.6.4Step 1: Start MongoDB. Issue the following command to start mongod:sudo service mongod startStep 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 stopStep 4: Restart MongoDB. Issue the following command to restart mongod:sudo service mongod restartStep 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.Install MongoDB Enterprise on SUSEOverviewUse 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.PrerequisitesTo 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-gssapiTo install these packages, you can issue the following command:sudo zypper install libopenssl0_9_8 net-snmp libsnmp15 snmp-mibs cyrus-sasl cyrus-sasl-gssapi32 Chapter 2. Install MongoDB 37. MongoDB Documentation, Release 2.6.4Install MongoDB EnterpriseNote: 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-stalledthe 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.4.tgztar -zxvf mongodb-linux-x86_64-subscription-suse11-2.6.4.tgzcp -R -n mongodb-linux-x86_64-subscription-suse11-2.6.4/ mongodbStep 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 EnterpriseStep 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/dbStep 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:mongodSpecify 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:/mongod2.1. Installation Guides 33 38. MongoDB Documentation, Release 2.6.4Specify 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 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.Install MongoDB Enterprise on Amazon Linux AMIOverviewUse 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.PrerequisitesTo 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-gssapiTo install these packages, you can issue the following command:sudo yum install openssl net-snmp net-snmp-libs net-snmp-utils cyrus-sasl cyrus-sasl-lib cyrus-sasl-devel Install MongoDB EnterpriseNote: 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-stalledthe 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.34 Chapter 2. Install MongoDB 39. MongoDB Documentation, Release 2.6.4curl -O http://downloads.10gen.com/linux/mongodb-linux-x86_64-subscription-amzn64-2.6.4.tgztar -zxvf mongodb-linux-x86_64-subscription-amzn64-2.6.4.tgzcp -R -n mongodb-linux-x86_64-subscription-amzn64-2.6.4/ mongodbStep 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 EnterpriseThe 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/mongodb.conf. See systemLog.path and storage.dbPath for additional information.If you change the user that runs the MongoDB process, you must modify the access control rights to the/var/lib/mongo and /var/log/mongodb directories to give this users access to these directories.Step 1: Create the data directory. Before you start MongoDB for the first time, create the directory to 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/dbStep 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:mongodSpecify 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:/mongodSpecify 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.2.1. Installation Guides 35 40. MongoDB Documentation, Release 2.6.4Step 5: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.Install MongoDB Enterprise on WindowsNew in version 2.6.OverviewUse 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.PrerequisitesMongoDB Enterprise Server for Windows requires Windows Server 2008 R2 or later. The MSI installer includes allother software dependencies.Install MongoDB EnterpriseStep 1: Download MongoDB Enterprise for Windows. Download the latest production release of MongoDBEnterprise19Step 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:testmongodb) and run it from there. The installation wizard includes an option to select aninstallation directory.Run MongoDB EnterpriseWarning: 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 datadb. Create this folder using the following commands from a Command Prompt:md datadbYou can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:C:mongodbbinmongod.exe --dbpath d:testmongodbdataIf your path includes spaces, enclose the entire path in double quotes, for example:19http://www.mongodb.com/products/mongodb-enterprise36 Chapter 2. Install MongoDB 41. MongoDB Documentation, Release 2.6.4C:mongodbbinmongod.exe --dbpath "d:testmongo db data"Step 2: Start MongoDB. To start MongoDB, run mongod.exe. For example, from the Command Prompt:C:Program FilesMongoDBbinmongod.exeThis 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-ingsome features of C:Program FilesMongoDBbinmongod.exe from communicating on networks.All users should select Private Networks, such as my home or work network and click Allowaccess. For additional information on security and MongoDB, please see the Security Documentation (page 281).Step 3: Connect to MongoDB. To connect to MongoDB through the mongo.exe shell, open another 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:mongodbbinmongo.exeIf you installation uses a different data directory, specify the directory when connecting, as in this example:C:mongodbbinmongod.exe --dbpath d:testmongodbdataIf your path includes spaces, enclose the entire path in double quotes. For example:C:mongodbbinmongod.exe --dbpath "d:testmongo db data"If you want to develop applications using .NET, see the documentation of C# and MongoDB20 for more information.Step 4: Begin using MongoDB. To begin using MongoDB, see Getting Started with MongoDB (page 43). Alsoconsider the Production Notes (page 188) document before deploying MongoDB in a production environment.Configure a Windows Service for MongoDB EnterpriseYou 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 FilesMongoDBlog"In the Command Prompt, create a configuration file for the logpath option for MongoDB:echo logpath="C:Program FilesMongoDBlogmongo.log" > "C:Program FilesMongoDBmongod.cfg"20http://docs.mongodb.org/ecosystem/drivers/csharp2.1. Installation Guides 37 42. MongoDB Documentation, Release 2.6.4Step 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 FilesMongoDBbinmongod.exe" --config "C:Program FilesMongoDBmongod.cfg" --installModify the path to the mongod.cfg file as needed.To use an alternate dbpath, specify the path in the configuration file (e.g. C:ProgramFilesMongoDBmongod.cfg) or on the command line with the --dbpath option.If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is datadb.If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service witha unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient systemresources exist and your system design requires it.Step 3: Stop or remove the MongoDB service as needed. To stop the MongoDB service use the following com-mand:net stop MongoDBTo remove the MongoDB service use the following command:"C:Program FilesMongoDBbinmongod.exe" --removeConfigure a Windows Service for MongoDB EnterpriseNote: There is a known issue for MongoDB 2.6.0, SERVER-1351521, which prevents the use of the instructionsin this section. For MongoDB 2.6.0, use Manually Create a Windows Service for MongoDB Enterprise (page 39) tocreate a Windows Service for MongoDB.You can set up the MongoDB server as a Windows Service that starts automatically at boot time.Step 1: Configure directories and files. Create a configuration file and a directory path for MongoDB logoutput (logpath):Create a specific directory for MongoDB log files:md "C:Program FilesMongoDBlog"In the Command Prompt, create a configuration file for the logpath option for MongoDB:echo logpath="C:Program FilesMongoDBlogmongo.log" > "C:Program FilesMongoDBmongod.cfg"Step 2: Run the MongoDB service. Run all of the following commands in Command Prompt with AdministrativePrivileges:Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option."C:Program FilesMongoDBbinmongod.exe" --config "C:Program FilesMongoDBmongod.cfg" --install21https://jira.mongodb.org/browse/SERVER-1351538 Chapter 2. Install MongoDB 43. MongoDB Documentation, Release 2.6.4Modify the path to the mongod.cfg file as needed.To use an alternate dbpath, specify the path in the configuration file (e.g. C:ProgramFilesMongoDBmongod.cfg) or on the command line with the --dbpath option.If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is datadb.If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service witha unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient systemresources exist and your system design requires it.Step 3: Stop or remove the MongoDB service as needed. To stop the MongoDB service use the following com-mand:net stop MongoDBTo remove the MongoDB service use the following command:"C:Program FilesMongoDBbinmongod.exe" --removeManually Create a Windows Service for MongoDB EnterpriseThe following procedure assumes you have installed MongoDB using the MSI installer, with the default pathC:Program FilesMongoDB 2.6 Enterprise.If you have installed in an alternative directory, you will need to adjust the paths as appropriate.Step 1: Open an Administrator command prompt. Press Win + R, then type cmd, then press Ctrl + Shift+ Enter.Execute the remaining steps from the Administrator command prompt.Step 2: Create directories. Create directories for your database and log files:mkdir c:datadbmkdir c:datalogStep 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:datalogmongod.log> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"echo dbpath=c:datadb>> "C:Program FilesMongoDB 2.6 Standardmongod.cfg"Step 4: Create the MongoDB service. Create the MongoDB service.sc.exe create MongoDB binPath= ""C:Program FilesMongoDB 2.6 Enterprisebinmongod.exe" --service sc.exe requires a space between = and the configuration values (eg binPath= ), and a to escape double quotes.If successfully created, the following log message will display:2.1. Installation Guides 39 44. MongoDB Documentation, Release 2.6.4[SC] CreateService SUCCESSStep 5: Start the MongoDB service.net start MongoDBStep 6: Stop or remove the MongoDB service as needed. To stop the MongoDB service, use the following com-mand:net stop MongoDBTo remove the MongoDB service, first stop the service and then run the following command:sc.exe delete MongoDB2.1.5 Verify Integrity of MongoDB PackagesOverviewThe 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.ConsiderationsMongoDB 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.pubReplace 2.2 with the appropriate release number to download public key. Keys are available for all MongoDBreleases beginning with 2.2.ProceduresUse PGP/GPGStep 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.tgz40 Chapter 2. Install MongoDB 45. MongoDB Documentation, Release 2.6.4Step 2: Download the public signature file.curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz.sigStep 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.ascYou 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.tgzYou 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 foundgpg 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 461CUse SHAMongoDB provides checksums using both the SHA-1 and SHA-256 hash functions. You can use either, as you like.Step 1: Download the MongoDB installation file. Download the binaries 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.tgzStep 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.sha2562.1. Installation Guides 41 46. MongoDB Documentation, Release 2.6.4Step 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.tgzwhich will generate this result:fe511ee40428edda3a507f70d2b91d16b0483674 mongodb-osx-x86_64-2.6.3.tgzEnter this command:cat mongodb-linux-x86_64-2.6.3.tgz.sha1which will generate this result:fe511ee40428edda3a507f70d2b91d16b0483674 mongodb-osx-x86_64-2.6.3.tgzThe 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.tgzwhich will generate this result:be3a5e9f4e9c8e954e9af7053776732387d2841a019185eaf2e52086d4d207a3 mongodb-osx-x86_64-2.6.3.tgzEnter this command:cat mongodb-linux-x86_64-2.6.3.tgz.sha256which will generate this result:be3a5e9f4e9c8e954e9af7053776732387d2841a019185eaf2e52086d4d207a3 mongodb-osx-x86_64-2.6.3.tgzThe output of the shasum and cat commands should be identical.Use MD5Step 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.tgzStep 2: Download the MD5 file.curl -LO http://downloads.mongodb.org/osx/mongodb-osx-x86_64-2.6.0.tgz.md5Step 3: Verify the checksum values for the MongoDB package file (Linux). Compute the checksum of the pack-agefile:md5 mongodb-linux-x86_64-2.6.0.tgzwhich will generate this result:42 Chapter 2. Install MongoDB 47. MongoDB Documentation, Release 2.6.4MD5 (mongodb-linux-x86_64-2.6.0.tgz) = a937d49