Installing MongoDB on Windows

As mentioned in a previous post, I will be spending some time learning, experimenting and working with the MongoDB NoSQL database.

MongoDB is a FOSS (Free of the Shelf Software) document-oriented database engine. It is one of the most popular engines in its classification. MongoDB Inc offers many free resources for developers to learn how to use their database. There are many books that offer from introduction to advanced information and examples on how to use this tool. I have been reading and experimenting with it for some years.

In 2013 I purchased the book “Seven Databases in Seven Weeks”. Chapter five is dedicated to MongoDB. At that time I decided to use Cassandra which is not covered in the book.

Earlier this year (2018) I purchased the book “MongoDB – The Definitive Guide”. In addition I have subscribed to some on-line courses on MongoDB offered by MongoDB University. I will comment on the courses in this blog as I complete them. Should be fun!

I like to read and then experiment in order to verify that I understand the concepts. For this reason I will be installing the MongoDB software on Windows and Linux machines. Both of these systems are on my home network.

Let’s start with the Windows download and installation. I pointed my Chrome browser to http://www.mongodb.org and it redirected me to https://www.mongodb.com where I located the download for Windows at https://www.mongodb.com/download-center?jmp=nav#community and proceeded to download the mongodb-win32-x86_64-2008plus-ssl-3.6.4-signed.msi installer to my c:\Temp folder.

Once the download completed, I clicked on the installer. You need to accept the end-user license agreement in order to install the software. I selected <Complete> in the “Choose Setup Type” window.

On the “Install MongoDB Compass” window I checked the “Install MongoDB Compass” checkbox and clicked on <Next>. Compass is an application that allows you to interact with the database without writing code. Is equivalent to “SQL Server Management Studio” on SQL Server. The installation took about 10 minutes on my computer. Have to let you know that the installation instructions for Windows in the “Appendix A – Installing MongoDB” section is quite out of date.

When the installation completes, I clicked on the <Finish> button to exit the Setup Wizard. By then the MongoDB Compass Community – Connect window was open and a License Agreement was displayed. Scroll to the bottom of the agreement and click on the <Agree> button.

A Welcome to MongoDB Compass Community page is displayed with some information. I used the <Next> button to scroll over the seven pages. I then clicked the <Get Started> button on the last page.

On the Privacy Settings window I left the three checkboxes checked and clicked on the <start Using Compass> button.

The Connect to Host page is displayed. I decided to leave all fields as they were. I did notice that Port setting (27017). I clicked on the <Connect> button. A top banner displayed with the following message “MongoDB not running on the provided host and port”.

The software was automatically installed in the following folder:

C:\Program Files\MongoDB\Server\3.6

Given the outdated and reduced set of instructions in the book, I used the following URL:

https://docs.mongodb.com/manual/installation/?_ga=2.5446579.1653473927.1525011980-1772120532.1525011980

Under MongoDB Community Edition section follow the Install on Windows link. It provides a current set of instructions.

To find out (should have done this for starters, but I already knew my Windows system was compatible) which version of Windows you are running, enter the following commands in a command prompt:

C:\ &gt;wmic os get caption
Caption
Microsoft Windows 10 Pro

C:\&gt; wmic os get osarchitecture
OSArchitecture
64-bit

Under the Run MongoDB Community Edition section follow the instructions in the (1) Set up the MongoDB environment.

Open a command prompt and enter the following commands:

Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\Users\John&gt; cd ..

C:\Users&gt; cd ..

C:\&gt; md \data\db

C:\&gt; dir c:\data\db
 Volume in drive C is OS
 Volume Serial Number is 26E8-87B0

 Directory of c:\data\db

04/29/2018  10:19 AM    &lt;DIR&gt;          .
04/29/2018  10:19 AM    &lt;DIR&gt;          ..
               0 File(s)              0 bytes
               2 Dir(s)  645,626,093,568 bytes free

The folder which will hold the MongoDB database has been created.

To manually start the MongoDB engine in interactive mode you must run the mongodb.exe executable. From the same command prompt you may enter:

C:\&gt;"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe"
2018-04-29T13:22:54.243-0700 I CONTROL  [initandlisten] MongoDB starting : pid=4536 port=27017 dbpath=C:\data\db\ 64-bit host=Condor
2018-04-29T13:22:54.243-0700 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2018-04-29T13:22:54.247-0700 I CONTROL  [initandlisten] db version v3.6.4
2018-04-29T13:22:54.261-0700 I CONTROL  [initandlisten] git version: d0181a711f7e7f39e60b5aeb1dc7097bf6ae5856
2018-04-29T13:22:54.268-0700 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2o-fips  27 Mar 2018
2018-04-29T13:22:54.269-0700 I CONTROL  [initandlisten] allocator: tcmalloc
2018-04-29T13:22:54.292-0700 I CONTROL  [initandlisten] modules: none
2018-04-29T13:22:54.310-0700 I CONTROL  [initandlisten] build environment:
2018-04-29T13:22:54.311-0700 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2018-04-29T13:22:54.346-0700 I CONTROL  [initandlisten]     distarch: x86_64
2018-04-29T13:22:54.353-0700 I CONTROL  [initandlisten]     target_arch: x86_64
2018-04-29T13:22:54.379-0700 I CONTROL  [initandlisten] options: {}
2018-04-29T13:22:54.401-0700 I -        [initandlisten] Detected data files in C:\data\db\ created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-04-29T13:22:54.408-0700 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=11774M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),cache_cursors=false,log=(enabled=true,a
rchive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-04-29T13:22:54.913-0700 I STORAGE  [initandlisten] WiredTiger message [1525033374:912954][4536:140735795978576], txn-recover: Main recovery loop: starting at 4/4608
2018-04-29T13:22:55.202-0700 I STORAGE  [initandlisten] WiredTiger message [1525033375:201958][4536:140735795978576], txn-recover: Recovering log 4 through 5
2018-04-29T13:22:55.402-0700 I STORAGE  [initandlisten] WiredTiger message [1525033375:402020][4536:140735795978576], txn-recover: Recovering log 5 through 5
2018-04-29T13:22:55.694-0700 I STORAGE  [initandlisten] WiredTiger message [1525033375:694042][4536:140735795978576], txn-recover: Set global recovery timestamp: 0
2018-04-29T13:22:55.880-0700 I CONTROL  [initandlisten]
2018-04-29T13:22:55.881-0700 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-04-29T13:22:55.885-0700 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2018-04-29T13:22:55.898-0700 I CONTROL  [initandlisten]
2018-04-29T13:22:55.902-0700 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
2018-04-29T13:22:55.925-0700 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server.
2018-04-29T13:22:55.940-0700 I CONTROL  [initandlisten] **          Start the server with --bind_ip 
&lt;address&gt; to specify which IP
2018-04-29T13:22:55.960-0700 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
2018-04-29T13:22:55.987-0700 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
2018-04-29T13:22:55.989-0700 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
2018-04-29T13:22:56.023-0700 I CONTROL  [initandlisten]
2018-04-29T13:22:56.039-0700 I CONTROL  [initandlisten]
2018-04-29T13:22:56.042-0700 I CONTROL  [initandlisten] ** WARNING: The file system cache of this machine is configured to be greater than 40% of the total memory. This can lead to increased memory pressure and poor performance.
2018-04-29T13:22:56.071-0700 I CONTROL  [initandlisten] See http://dochub.mongodb.org/core/wt-windows-system-file-cache
2018-04-29T13:22:56.074-0700 I CONTROL  [initandlisten]
2018-04-29T15:22:56.767-0500 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/data/db/diagnostic.data'
2018-04-29T15:22:56.775-0500 I NETWORK  [initandlisten] waiting for connections on port 27017

Note on the last line that the database is up and running and listening on port 27017. This is the same port that will be used by Compass to access the database.

At this time I started Compass and was able to connect to MongoDB.

There are additional ways to connect to MongoDB described in the web page. I just did not feel like exploring them at this time; but will do in the future.

Went to the Configure a Windows Service for MongoDB Community Edition section and followed the steps described.

(1) Open an Administrator command prompt

Microsoft Windows [Version 10.0.16299.371]
(c) 2017 Microsoft Corporation. All rights reserved.

C:\WINDOWS\system32&gt; cd ..

C:\Windows&gt; cd ..

C:\&gt;

(2) Create directories

From an administrator command prompt:

C:\&gt;mkdir c:\data\log

C:\&gt; dir c:\data\log
 Volume in drive C is OS
 Volume Serial Number is 26E8-87B0

 Directory of c:\data\log

04/29/2018  10:42 AM    &lt;DIR&gt;          .
04/29/2018  10:42 AM    &lt;DIR&gt;          ..
               0 File(s)              0 bytes
               2 Dir(s)  645,309,353,984 bytes free

Note that at this time I skipped the creation of the c:\data\db folder because I had already created it in a previous step.

(3) Create a configuration file

Opened Notepad++ (you could use Notepad which comes with Windows) with Run as administrator and created the file:

C:\Program Files\MongoDB\Server\3.6\mongod.cfg

In the file I added the following lines:

systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db

(4) Install the MongoDB service

At this time, MongoDB was running from a console and I also had Compass openedClosed the Compass window and on the command console running mongod.exe I entered <CONTROL>C

:::: :::: ::::
-29T11:01:14.997-0500 I CONTROL  [thread7] Ctrl-C signal
-29T11:01:14.998-0500 I CONTROL  [consoleTerminate] got CTRL_C_EVENT, will terminate after current cmd ends
-29T11:01:15.000-0500 I NETWORK  [consoleTerminate] shutdown: going to close listening sockets...
-29T11:01:15.003-0500 F CONTROL  [thread6] Encountered an error in PeriodicRunnerASIO: The I/O operation has been aborted because of either a thread exit or an application request.
-29T11:01:15.005-0500 I FTDC     [consoleTerminate] Shutting down full-time diagnostic data capture
-29T11:01:16.012-0500 I STORAGE  [consoleTerminate] WiredTigerKVEngine shutting down
-29T11:01:16.557-0500 I STORAGE  [consoleTerminate] shutdown: removing fs lock...
-29T11:01:16.557-0500 I CONTROL  [consoleTerminate] now exiting
-29T11:01:16.560-0500 I CONTROL  [consoleTerminate] shutting down with code:12

I then closed the command console window.

On the administrator command console I entered:

C:\&gt;"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\3.6\mongod.cfg" --install

I then opened the Services utility in Windows and MongoDB had been installed as a service.

(5) Start the MongoDB service

You can start services in Windows from the services utility or from a command prompt. On the services windows you right click on MongoDB and select Start from the popup menu. Starting the MongoDB service from an administrator command console is illustrated by the following screen capture:

C:\&gt; net start MongoDB
The MongoDB service is starting..
The MongoDB service was started successfully.

(6) Verify that MongoDB has started successfully

You can check in the c:\datalog\mongod.log file by looking for the following line:

2018-04-29T12:56:39.596-0500 I STORAGE  [initandlisten] Service running

(7) Connect to MongoDB

The simplest way is to use the Compass application. That takes between 10 to 15 seconds.

You can open a command console and type:

C:\&gt; net start
These Windows services are started:

   Adobe Acrobat Update Service
   Application Host Helper Service
   Application Information
:::: :::: ::::
   IPsec Policy Agent
   Local Session Manager
   Message Queuing
   MongoDB
   MySQL56
   Net.Msmq Listener Adapter
   Net.Pipe Listener Adapter
:::: :::: ::::

(8) Stop or remove the MongoDB service as needed

There are at least two ways to get this task accomplished.

One can use the service window, select the MongoDB service, right click and select Stop.

On the other hand, one can open an administrator command console and stop the service by entering:

C:\&gt; net stop MongoDB
The MongoDB service is stopping.
The MongoDB service was stopped successfully.

My suggestion is to navigate to the following page:

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/#overview

And follow the directions. The information appears to be up to date with the latest stable release of MongoDB.

I was planning on having time to proceed and document the installation of MongoDB on Linux. It seems that collecting, formatting and generating the post took more time than what I expected. It will get done over the next weekend. I want to make sure I have at least two instances of MongoDB running on the network.

As usual, if you have comments or questions please leave me a note or send me a message via e-mail.

John

john.canessa@gmail.com

@john_canessa

Leave a Reply

Your email address will not be published. Required fields are marked *