Click here to Skip to main content
Click here to Skip to main content

MongoDB Installation Scripts for Windows

, 17 Mar 2014
Rate this:
Please Sign up or sign in to vote.
Batch scripts that help install MongoDB on a Windows PC

Introduction

I personally appreciate the fact that MongoDB does not come with a Windows installer. Instead, it is left to the developer to determine where to install MongoDB, and how to configure it. This provides flexibility, and makes MongoDB easier to integrate and distribute with a software application.

But even though there are advantages to the "manual" installation approach, there are also disadvantages. Developers often have to remind themselves of how the installation procedure works, and they often forget one or two configuration settings. Manual installations are all-too-often performed inconsistently, causing unique problems that only occur on the local system. To help mitigate these types of problems, I have created a set of MongoDB batch scripts which make it easier to install, configure, and uninstall MongoDB on a Windows PC.

Background

Relevant background can be found in the link below, from the MongoDB website.

Using the Code

Project Files

This project consists of the following six Windows Batch scripts:

  1. MongoDB.bat - This batch script is responsible for installing, configuring, and running MongoDB. This script should never be run directly, but instead is called by other scripts.
  2. MongoDB-RunCommandLine.bat - This batch script installs and configures MongoDB, and runs it in a command-line window. Terminating the script (or closing the window) causes MongoDB to stop.
  3. MongoDB-ServiceInstall.bat - This batch script installs and configures MongoDB as a Windows Service.
  4. MongoDB-ServiceStart.bat - This batch script starts the MongoDB Windows Service.
  5. MongoDB-ServiceStop.bat - This batch script stops the MongoDB Windows Service.
  6. MongoDB-ServiceUninstall.bat - This batch script uninstalls the MongoDB Windows Service.

Installation Procedure

To install MongoDB for the first time, follow these steps:

  1. Download the MongoDB Installation Scripts presented in this article, unzip them, and place them into a convenient directory.

  2. Download the MongoDB installation file from the MongoDB website, unzip it, and place it in the same folder as the MongoDB Installation Scripts.
    (See the MongoDB downloads page: http://www.mongodb.org/downloads)

  3. Rename the MongoDB directory to simply "mongodb".

  4. Install MongoDB using one of the two installation batch scripts:
    1. For command-line installation: double-click the MongoDB-RunCommandLine.bat script, or run it as Administrator by right-clicking on the MongoDB-RunCommandLine.bat file and choosing "Run as administrator". This action will run MongoDB on the MS-DOS command-line, where it will continue to run for as long as the command-line window stays open!


    2. For Windows Service installation: double-click the MongoDB-ServiceInstall.bat script, or run it as Administrator by right-clicking on the MongoDB-ServiceInstall.bat file and choosing "Run as administrator". This action will install the MongoDB service into the Windows services panel.

Maintenance and Best Practices

  1. Uninstalling the MongoDB Windows Service

    The MongoDB Windows Service can be uninstalled by double-clicking the
    MongoDB-ServiceUninstall.bat script, or by running it as Administrator by right-clicking on the
    MongoDB-ServiceUninstall.bat file and choosing "Run as administrator".

  2. Starting and Stopping the MongoDB Windows Service

    Once you have installed MongoDB as a service, you can run the MongoDB-ServiceStart.bat and
    MongoDB-ServiceStop.bat scripts to start and stop the MongoDB Windows Service.

  3. MongoDB Configuration

    Whenever you install MongoDB as a service or run it on the command-line, the MongoDB.bat script always checks whether a mongod.conf file exists in the installation directory. If not, a default configuration file is created for you. To customize MongoDB, place all of your configuration settings in this file, and be sure to backup this file periodically!

  4. Moving the MongoDB Installation Directory

    Once you have installed MongoDB as a service or run it on the command-line, moving the MongoDB installation directory itself will cause MongoDB to fail. To move the MongoDB installation directory safely, first stop MongoDB, then move the installation folder, and then update the paths defined in the mongod.conf. Once these paths have been updated, MongoDB should run properly again.

Points of Interest

Technical Details

After you have installed MongoDB for the first time, you will notice a few files and directories appear. A "log" directory will appear, containing the MongoDB log. A "data" directory will also appear, which contains a second directory named "db". This is where the MongoDB database files are stored. A mongod.conf file will also appear in the base directory. This file can be modified to configure MongoDB.

Advantages of Use

  • Provides a predictable baseline to work with when installing MongoDB on Windows.
  • Helps automate the installation process on customer machines.

History

  • 2014/03/17 - First release
  • 2014/03/19 - Article updated with installation instructions and more technical details

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

x3F

United States United States
No Biography provided

Comments and Discussions

 
QuestionThe zip file is corrupted PinmemberNnamezie27-Mar-14 0:08 
AnswerRe: The zip file is corrupted Pinmemberx3F1-Apr-14 1:47 
SuggestionGood Pinmemberdaniero24-Mar-14 7:33 
GeneralRe: Good Pinmemberx3F1-Apr-14 1:43 
Generalgood job! Pinmemberfreed_yang17-Mar-14 17:08 
GeneralMy vote of 5 Pinmemberfreed_yang17-Mar-14 17:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 17 Mar 2014
Article Copyright 2014 by x3F
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid