- Install MongoDB >
- Install MongoDB on Windows
Install MongoDB on Windows¶
Platform Support
Starting in version 2.2, MongoDB does not support Windows XP. Please use a more recent version of Windows to use more recent releases of MongoDB.
Important
If you are running any edition of Windows Server 2008 R2 or Windows 7, please install a hotfix to resolve an issue with memory mapped files on Windows.
Download MongoDB for Windows¶
There are three builds of MongoDB for Windows:
- MongoDB for Windows Server 2008 R2 edition (i.e. 2008R2) only runs on Windows Server 2008 R2, Windows 7 64-bit, and newer versions of Windows. This build takes advantage of recent enhancements to the Windows Platform and cannot operate on older versions of Windows.
- MongoDB for Windows 64-bit runs on any 64-bit version of Windows newer than Windows XP, including Windows Server 2008 R2 and Windows 7 64-bit.
- MongoDB for Windows 32-bit runs on any 32-bit version of Windows newer than Windows XP. 32-bit versions of MongoDB are only intended for older systems and for use in testing and development systems. 32-bit versions of MongoDB only support databases smaller than 2GB.
Tip
To find which version of Windows you are running, enter the following command in the Command Prompt:
Download the latest production release of MongoDB from the MongoDB downloads page. Ensure you download the correct version of MongoDB for your Windows system. The 64-bit versions of MongoDB will not work with 32-bit Windows.
Extract the downloaded archive.
- In Windows Explorer, find the MongoDB download file, typically in
the default
Downloads
directory. - Extract the archive to
C:\
by right clicking on the archive and selecting Extract All and browsing toC:\
.
- In Windows Explorer, find the MongoDB download file, typically in
the default
Optional. Move the MongoDB directory to another location. For example, to move the directory to
C:\mongodb
directory:Go Start Menu > All Programs > Accessories.
Right click Command Prompt, and select Run as Administrator from the popup menu.
In the Command Prompt, issue the following commands:
Note
MongoDB is self-contained and does not have any other system
dependencies. You can run MongoDB from any folder you choose. You
may install MongoDB in any directory (e.g. D:\test\mongodb
)
Run MongoDB¶
Set Up the Data Directory¶
MongoDB requires a data folder to store its files. The
default location for the MongoDB data directory is C:\data\db
.
Create this folder using the Command Prompt. Go to the
C:\
directory and issue the following command sequence:
You can specify an alternate path for data files using the
--dbpath
option to mongod.exe
.
Start MongoDB¶
To start MongoDB, execute from the Command Prompt:
This will start the main MongoDB database process. The waiting for
connections
message in the console output indicates that the
mongod.exe process is running successfully.
Note
Depending on the security level of your system, Windows will issue
a Security Alert dialog box about blocking “some
features” of C:\\mongodb\bin\mongod.exe
from communicating on
networks. All users should select Private Networks, such as my
home or work network
and click Allow access
. For additional
information on security and MongoDB, please read the
Security Concepts page.
Warning
Do not allow mongod.exe
to be accessible to public
networks without running in “Secure Mode” (i.e. auth
.)
MongoDB is designed to be run in “trusted environments” and the
database does not enable authentication or “Secure Mode” by
default.
You may specify an alternate path for \data\db
with the
dbpath
setting for mongod.exe
, as in the
following example:
If your path includes spaces, enclose the entire path in double quotations, for example:
Connect to MongoDB¶
Connect to MongoDB using the ~bin.mongo.exe
shell. Open another
Command Prompt and issue the following command:
Note
Executing the command start C:\mongodb\bin\mongo.exe
will
automatically start the mongo.exe
shell in a separate
Command Prompt window.
The ~bin.mongo.exe
shell will connect to mongod.exe
running on
the localhost interface and port 27017
by default. At the
~bin.mongo.exe
prompt, issue the following two commands to
insert a record in the test
collection of the default
test
database and then retrieve that record:
See also
mongo
and mongo Shell Methods. If
you want to develop applications using .NET, see the documentation
of C# and MongoDB for more
information.
MongoDB as a Windows Service¶
New in version 2.0.
You can set up MongoDB as a Windows Service so that the database will start automatically following each reboot cycle.
Note
mongod.exe
added support for running as a Windows
service in version 2.0, and mongos.exe
added support for
running as a Windows Service in version 2.1.1.
Configure the System¶
The following steps, although optional, are good practice.
You should specify two options when running MongoDB as a Windows
Service: a path for the log output (i.e. logpath
) and a
configuration file.
Optional. Create a specific directory for MongoDB log files:
Optional. Create a configuration file for the
logpath
option for MongoDB in the Command Prompt by issuing this command:
Note
Consider setting the logappend
option. If you do not,
mongod.exe
will delete the contents of the existing log
file when starting.
Install and Run the MongoDB Service¶
Run all of the following commands in Command Prompt with “Administrative Privileges:”
To install the MongoDB service:
Modify the path to the
mongod.cfg
file as needed. For the--install
option to succeed, you must specify alogpath
setting or the--logpath
run-time option.To run the MongoDB service:
If you wish to use an alternate path for your dbpath
specify it in the config file (e.g. C:\mongodb\mongod.cfg
) on
that you specified in the --install
operation. You may also specify --dbpath
on the command line; however, always prefer the configuration file.
If you have not set up the data directory, set up the data
directory where MongoDB will store its data
files. If the dbpath
directory does not exist,
mongod.exe
will not be able to start. The default value for
dbpath
is \data\db
.