Home  >  Blog  >   MongoDB

Installation of MongoDB on Windows

Rating: 4
  
 
7025

Installation of MongoDB is pretty easy, to run the installer downloaded from the downloads section here. The pre-requisites of the installation is just a Windows system and the MongoDB installer from the step above. Let’s check the Official MongoDB downloads section for the right zip file to download.

From MongoDB version 2.2, installation does not support Windows XP anymore and hence is suggested to choose to install on Windows Vista or Windows 7 or on Windows Server 2008 R2.

If you want to enrich your career and become a professional in MongoDB, then visit Mindmajix - a global online training platform: "MongoDB TrainingThis course will help you to achieve excellence in this domain. 

MongoDB on Windows

Related blog: MongoDB Atlas

The downloaded file: mongodb-win32-x86_64-2008plus-3.4.7-signed.msi. Having said that, let’s get down to business installing the above.

MindMajix Youtube Channel

MongoDB Installation (Interactive / Manual Installation)

Once the download finishes, identify the downloaded installer file and double-click the .msi file to initiate the installation process, which will take you through the following installation screens.

A point to remember is that MongoDB is a self-contained database and hence doesn’t have any other system dependencies along with it. Once the installation is complete, you can run MongoDB from any folder of your choice.

MongoDB Install SetUp

Click Next on the screen above

MongoDB Installation Agreement

Click on the ‘I accept the terms in the License Agreement’ checkbox and then click on the Next button.

MongoDB Installation - SetUp Type

Click on the ‘Complete’ button to progress further, if you wish that the installer chose the directory and what needs to be installed on the Computer (which is by default, the recommended option), but if you want to be choosy in what needs to be installed and where each of these components to be installed then you may go with the ‘Custom’ option.

MongoDB - Ready to Install

Considering that you’ve chosen to go by the recommended option of ‘Complete’, the above screen appears to trigger the actual installation process by clicking on the Install button.

MongoDB Installing ScreenShot

Once the installation process completes, this is the screen that confirms it.

MongoDB Installation Completed

Clicking on the Finish button finishes the process.

Frequently Asked MongoDB Interview Questions

Installation of MongoDB in a Silent / Unattended way

In the process above, you were able to control the installation process and it was an interactive process wherein your key in your requirements and based on that the installation progresses. Here we are going to introduce to you a way of installing MongoDB in a silent or an unattended manner using the MongoDB command-line utility.

Take a look at the following steps on how to do the same:

  • Open a command prompt in Administrator mode (On the Run command, type cmd.exe and press CTRL + SHIFT + Enter to open Command Prompt in the administrator mode.)
  • From the command prompt that’s opened in the administrator mode, traverse to the location where the MongoDB installer is downloaded and run the following command
msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.4.7-signed.msi ^               
     INSTALLLOCATION="C:Program FilesMongoDBServer3.4.7" ^                                     
     ADDLOCAL="all"
  • You can choose to give a different folder path (if needed) by modifying the INSTALLLOCATION parameter in the command run earlier.
  • To install specific MongoDB component sets, you can choose from the list given below and use them in the ADDLOCAL parameter (using a comma-separated list) in the command provided earlier.
  • Server
  • Router
  • Client
  • MonitoringTools
  • ImportExportTools
  • miscellaneous tools

For example, if we want to install only the MongoDB Server and Client on your system then you can choose to run the following command only to install these two components.

msiexec.exe /q /i mongodb-win32-x86_64-2008plus-ssl-3.4.7-signed.msi ^           
      INSTALLLOCATION="C:Program FilesMongoDBServer3.4.7" ^           
      ADDLOCAL="Server,Client"

The steps above enable you to install the MongoDB related components via the interactive installer installation or the silent installation (the choice is all yours). Now that we have installed the MongoDB database, let us see how we can run this to start the database as such.

Checkout MongoDB Tutorial

Run MongoDB Community Edition via Utilities

A point to note here that by design, MongoDB should be run in trusted environments and the database doesn’t support ‘Secure mode’ by default. Hence it is very important that we don’t make mongod.exe visible and vulnerable on public networks without running it in ‘Secure mode’ with the needed authentication settings. With those points discussed, let’s set up our MongoDB one time configurations to get it started.

MongoDB requires a data directory in order to persist all the data. The default data directory path for MongoDB is the absolute path datadb on the drive where we start the MongoDB service.

Or we can choose a specific folder path by using the –dbpath parameter while we run the mongod.exe. If your path contains spaces then you need to add the path using double quotation marks, else you can use it as shown below.

"C:Program FilesMongoDBServer3.4binmongod.exe" --dbpath E:MongoDBdata

  • To start the MongoDB database, simply run the mongodb.exe using the command given below on a Command prompt. If you can wait and check for the following string “waiting for connections”, then it is evident that the mongod.exe process is running successfully

"C:Program FilesMongoDBServer3.4binmongod.exe"

  • To connect to the MongoDB we can use the mongo.exe shell, by opening it in another command prompt using the command shown as below:

"C:Program FilesMongoDBServer3.4binmongo.exe"

  • To stop the MongoDB database instance, you can press CTRL + C on the same command prompt terminal where the mongod instance was running earlier.

How to Configure a Windows Service for MongoDB Community Edition?

Earlier, you’ve seen how to start the MongoDB services via the MongoDB utilities. This section talks about creating a Windows service to start and stop MongoDB services via the Services tool, let’s see how this can be achieved:

  • On the Run command, type cmd.exe and press CTRL + SHIFT + ENTER to open the Command Prompt in Administrative mode (or as an Administrator).
  • Create the following directories for your database and the corresponding log files that your database is going to write in the future:

mkdir E:MongoDBdb

mkdir E:MongoDBlog

  • Create a configuration file, systemLog.path to redirect all the diagnostic logging information from the mongod and mongos services. Any other additional configuration that is needed can also be made at this point, please refer to the Official MongoDB documentation for this purpose.

You can create this configuration file under the MongoDB installation path,

“C:Program FilesMongoDBServer3.4mongo.cfg” specifying both the systemLog.path and storage.dbPath.

systemLog:
    destination: file
    path: E:MongoDBlogmongod.log
storage:
    dbPath: E:MongoDBdb
  • Open a command prompt as an Administrator and install the MongoDB service by using the mongod.exe command and also using the –install option and then to use –config option to mention the configuration file created in the step above.

"C:Program FilesMongoDBServer3.4binmongod.exe" --config "C:Program FilesMongoDBServer3.4mongod.cfg" –install

  • You can install the services with a meaningful name using the – serviceName and – serviceDisplayName parameters for each of mongod.exe and mongos.exe.

  • You can run the following command to start the MongoDB service

net start MongoDB

  • To stop the MongoDB service, you can run the following command

net stop MongoDB

  • To remove or to uninstall the MongoDB services, you can use the following command

"C:Program FilesMongoDBServer3.4binmongod.exe" –remove

Join our newsletter
inbox

Stay updated with our newsletter, packed with Tutorials, Interview Questions, How-to's, Tips & Tricks, Latest Trends & Updates, and more ➤ Straight to your inbox!

Course Schedule
NameDates
MongoDB Training Apr 27 to May 12View Details
MongoDB Training Apr 30 to May 15View Details
MongoDB Training May 04 to May 19View Details
MongoDB Training May 07 to May 22View Details
Last updated: 03 Apr 2023
About Author

Prasanthi is an expert writer in MongoDB, and has written for various reputable online and print publications. At present, she is working for MindMajix, and writes content not only on MongoDB, but also on Sharepoint, Uipath, and AWS.

read more