How to install MongoDB on Windows?
Installation of MongoDB is pretty easy, to run the installer downloaded from 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.
MongoDB " "
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.
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 the 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.
Click Next on the screen above
Click on ‘I accept the terms in the License Agreement’ checkbox and then click on the Next button.
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.
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.
Subscribe to our youtube channel to get new updates..!
Once the installation process completes, this is the screen that confirms it.
Clicking on Finish button finishes the process.
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 you 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
- 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.
- 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.
Steps above enables you to install the MongoDB related components via the interactive installer installation or the silent installation (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.
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
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:
To stop 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 future:
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.
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