Installing MongoDB Shell (Old Version) on Windows and Setting up as a Service

Written by: amit kumar  || 
April 9th 2024, 9:57 am

In some cases, you might need to work with older versions of MongoDB for testing or legacy purposes. This tutorial guides you through the process of installing an older version of MongoDB Shell on a Windows machine and configuring it to run as a service automatically on boot.

Prerequisites

- Windows operating system - Basic familiarity with the Windows command line

Steps

1. Download MongoDB Shell (Old Version)

- Visit the MongoDB archive releases page (https://www.mongodb.com/download-center/community/releases/archive) to download the desired version. For this tutorial, we'll use version 4.2.14. - Navigate to the Windows section and download the ZIP file for version 4.2.14.

2. Extract and Place MongoDB Shell Files

- After downloading, extract the contents of the ZIP file. - Locate the `bin` folder within the extracted files. - Move the `bin` folder to `C:\Program Files\MongoDB\mongoshell\`.

free reusme builder

3. Set Environment Variables

- Open the Environment Variables settings on your Windows machine. - Add `C:\Program Files\MongoDB\mongoshell\` to the `PATH` variable. - Save the changes.

free reusme builder

4. Prepare Data and Log Directories

- Create two directories: - `C:\data\db` (for database files) - `C:\data\log` (for log files)

free reusme builder

Create a Configuration File

- Create a configuration file named `mongod.cfg` in a convenient location. - Add the following configuration settings to `mongod.cfg`:

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

Restart Your PC

- Restart your computer to apply the environment variable changes.

7. Install MongoDB Shell as a Service

- Open Command Prompt with administrator privileges. - Execute the following command:

mongod --config "C:\path\to\mongod.cfg" --install

Replace `"C:\path\to\mongod.cfg"` with the actual path to your configuration file.

Start MongoDB Service

- After installing MongoDB as a service, start the service by running:

net start MongoDB

9. Verify Service Status

- Confirm that the MongoDB service is running properly by checking for its status. - You can use MongoDB Compass or the command line to connect and interact with the MongoDB instance.

free reusme builder

Conclusion

Congratulations! You have successfully installed an older version of MongoDB Shell on your Windows machine and configured it to run as a service automatically on boot. You can now use this setup for testing or working with legacy databases.

Subscribe to our tech blogs