In this blog post, we will show how to install MongoDB on Windows.
Download installer
First go to the MongoDB download center https://www.mongodb.com/download-center#community. According to your Windows server version, click on the green buton and download the installer (.msi).
In our example, we will use the MongoDB Community version for Windows Server 2008 and later.
Important: MongoDB is available exclusively for Windows 64 bits.
To check the Windows version you are running:
Install MongoDB
Get the installer:
Now, follow the next installation steps.
Accept the terms.
You can choose your installation method. For a customized installation, use the “custom” method. For instance, you can choose your installation drive location.
After choosing your installation path, click on next.
Well, your installation is now finished.
Check the installation by command line (powershell):
cd "C:\Program Files\MongoDB\Server\3.2\bin" PS C:\Program Files\MongoDB\Server\3.2\bin> ls Directory: C:\Program Files\MongoDB\Server\3.2\bin Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 11/18/2016 5:45 PM 7145663 bsondump.exe -a--- 9/2/2016 10:43 PM 1991680 libeay32.dll -a--- 11/18/2016 5:52 PM 9494016 mongo.exe -a--- 11/23/2016 12:20 PM 321 mongod.cfg -a--- 11/23/2016 12:19 PM 325 mongod.cs -a--- 11/18/2016 5:56 PM 19520512 mongod.exe -a--- 11/18/2016 5:56 PM 161075200 mongod.pdb -a--- 11/18/2016 5:48 PM 9228030 mongodump.exe -a--- 11/18/2016 5:47 PM 7393229 mongoexport.exe -a--- 11/18/2016 5:46 PM 7318208 mongofiles.exe -a--- 11/18/2016 5:47 PM 7432777 mongoimport.exe -a--- 11/18/2016 5:48 PM 7154618 mongooplog.exe -a--- 11/18/2016 5:57 PM 16767488 mongoperf.exe -a--- 11/18/2016 5:47 PM 10548404 mongorestore.exe -a--- 11/18/2016 5:56 PM 7959040 mongos.exe -a--- 11/18/2016 5:56 PM 85716992 mongos.pdb -a--- 11/18/2016 5:46 PM 7401410 mongostat.exe -a--- 11/18/2016 5:48 PM 7287874 mongotop.exe -a--- 9/2/2016 10:43 PM 321536 ssleay32.dll PS C:\Program Files\MongoDB\Server\3.2\bin>
Setup the MongoDB Environment
MongoDB can be setting up by two ways:
- Command line options
- Configuration file options
We will use the configuration file method.
Create the following MongoDB data directory:
C:\mongodb\data\
You can also create a directory for each MongoDB instances in order to separate your data files between instances:
C:\mongodb\data\MDBx
Create the log directory:
C:\mongodb\logs\
As for the data files, you should have a separation of logs between instances:
C:\mongodb\logs\MDBx
MongoDB configuration file:
To run MongoDB with your configuration parameters, create a Mongodb configuration file and use it when you start mongod process.
Insert the following lines in your configuration files:
#MongoDB Configuration file example dbpath = C:\mongodb\data\MDB1 port = 27001 logpath = C:\mongodb\logs\MDB1\mongod.log
Save the file with the .cfg extension (full path), and starting the process from command prompt:
.\mongod.exe -f mongod.cfg
Connect to the mongo shell:
PS C:\Program Files\MongoDB\Server\3.2\bin> .\mongo.exe --host 127.0.0.1:27001
Create a MongoDB Windows service:
Install a Windows service with the following options:
PS C:\Program Files\MongoDB\Server\3.2\bin> .\mongod.exe -f "C:\Program Files\MongoDB\Server\3.2\bin\mongod.cfg" --install --serviceName mdb1
A new service is now created: