Sunday, 4 December 2016

Installing MongoDB on Windows 10

Here we will run through an installation of MongoDB 3.4.0 on Windows 10

Step 1: Download
Click the "Download" button on the top-right of the banner on any mongodb.com page to go to their download centre and download your preferred flavour of MongoDB


Click the Download button and save the installer file. Run it when the download completes.

Step 2: Install
Run the installer and click "Next" to confirm you want to go through the Setup:


Accept the License Agreement and click "Next": 

You can choose Complete or Custom Setup:
Choose Complete Installation unless you really need to change something.

Custom Setup gives you a bit more control of the components to install:
It's not really worth bothering with and you can always come back if you find need to change some component.

The executable installed with each component are:
ComponentExecutable
Servermongod.exe
Routermongos.exe
Clientmongo.exe
MonitoringToolsmongostat.exe, mongotop.exe
ImportExportToolsmongodump.exe, mongorestore.exe, mongoexport.exe, mongoimport.exe
MiscellaneousToolsbsondump.exe, mongofiles.exe, mongooplog.exe, mongoperf.exe

Click "Next" on your choice of Complete or Custom Installation and the installation is ready to begin:
 Click "Install". You may get a Windows security pop-up asking if you want to allow the installer to make these changes, if so, simply click "Yes".

The Installation will begin in a few seconds:

When done, you should see the successful Completion message:

And that's all there is to it.

The files should be installed to C:\Program Files\MongoDB\

Step 2.2 (optional): Change, Repair or Remove Installation
Running the Installer again will allow you make changes to your installation:


"Change" takes you back to the Custom Installation screen where you can add or remove selected components. "Remove" will Uninstall MongoDB from your PC.

Step 3: Configure the environment for MongoDB
Before we can run MongoDB we need to do a bit of Windows configuration.

Firstly, start a Windows Command prompt. Find the Command Prompt icon on the Start Menu or hit R+Windows key and type "cmd" to have Windows find it. Right-click and choose Run As Administrator. When it's running it looks like this:

MongoDB needs a data directory to store files. By default this is \data\db under the current volume, so we could create this in our Command Prompt window with:
mkdir c:\data\db


We could create our data directory in a different location, but then would always need to tell MongoDB this location at runtime. Keeping to the default is easier for now.

We can add a default log directory too:
mkdir c:\data\log

To make running MongoDB executables easier, it helps to add their location to your path. Launch System Settings from the Windows Control Panel, and select Environment Variables on the Advanced tab:

Add a New entry "C:\Program Files\MongoDB\Server\3.4\bin" to your path:

Now Windows will look for executables in this directory.



Step 4: Starting MongoDB
Now we can start our MongoDB server from the Windows Command Prompt. This is done by running the mongod executable.

It can be started with various options. To see what they are we can execute with the help option:
mongod --help
This will just print the help and exit.

If the MongoDB directory has been added to the Windows path as described above then we can simply type the name of the executable we want to run:
mongod
otherwise we need to specify the full path ourselves:
C:\"Program Files"\MongoDB\Server\3.4\bin\mongod

Either way, this should start the mongod process running and writing log messages to your Command window.

Your firewall program may now detect the MongoDB network processes and ask you what to do:
I chose to disable all access here. You can always change the config later in the Firewall controls.

When you see the message:
 NETWORK  [thread1] waiting for connections on port 27017
then your MongoDB is up and running:
 
Starting mongod


Hit CTRL-C to stop it.

This basic installation will be good enough for playing around and learning with MongoDB.

More advanced installation topics can be found here:

To connect to our MongoDB we will use the MongoDB shell, which we will look at here






13 comments:

  1. How to install MongoDB in window simple and new detail
    http://programmershelper.com/installation-mongodb-on-windows

    ReplyDelete
  2. That's a great write-up. The way you write is very nice. Thanks for this special article. Do you have any idea about the Turkish visa for US citizens ? Yes, It is a necessary permit for US Citizens to enter turkey. If you don't have a Visa you should not start your journey . Firstly you should take a visa and then start your journey . All the important information about the turkey visa is available on this page . By the 1 click you can read all the information .

    ReplyDelete