How to check version and update MongoDB on Windows

Updated: February 1, 2024 By: Guest Contributor Post a comment

Introduction

MongoDB is a popular NoSQL database that is widely used in modern web applications. If you are working on a Windows operating system, keeping MongoDB up to date is crucial to take advantage of the latest features, improvements, and security patches. This tutorial outlines the steps needed to check your currently installed MongoDB version and update it to the latest release.

Checking Your MongoDB Version

Before updating MongoDB, it’s important to check the version you currently have installed. You can easily find this information by running the following command in the Command Prompt:

mongod --version

The output will provide you with your MongoDB version, along with additional details about the build:

db version v4.4.4
Build Info: {...}

It’s also possible to check the MongoDB version from within the mongo shell. Start the shell using:

mongo

And then, within the shell, run:

db.version()

You will receive the version number as output. For example:

4.4.4

Updating MongoDB on Windows

Now that you know your current MongoDB version, you can proceed with updating it. Here are the steps to follow:

Step 1 – Backup Your Data

Before you proceed with any update, ensure that you backup your database data. Use the mongodump tool to create a backup:

mongodump --out "/path/to/backup/directory"

Replace the placeholder with the desired location for your database backup.

Step 2 – Download the Latest MongoDB Version

Visit the official MongoDB Download Center (link) to download the latest MongoDB community server installer for Windows. Choose the version corresponding to your Windows architecture (32-bit or 64-bit) and the package you desire, then click ‘Download’.

Step 3 – Uninstall the Old Version

Before installing a new version of MongoDB, you should first uninstall the old version. Head to the ‘Control Panel’, go to ‘Programs’ and then ‘Programs and Features’. Find MongoDB from the list of installed programs, click it, and press ‘Uninstall’.

Remember, having properly backed up your data prevents loss during this step.

Step 4 – Install the New Version

Run the installer you downloaded from the MongoDB website. Accept the license agreement and choose the setup type (complete or custom). You will also be asked whether you want to install MongoDB Compass, the official GUI for MongoDB, which is optional.

Follow the installer’s instructions to complete the installation process. Once the installation is finished, you can remove the old MongoDB data directory, if you desire, or have the new version utilize it.

Step 5 -Restore Your Data

After the new version is installed, use mongorestore to restore your database data from the backup:

mongorestore /path/to/backup/directory

If you didn’t change the default data directory and your version update was minor, MongoDB should automatically recognize and use your existing databases. However, for major updates or if you specified a custom data directory, you may need to use `mongorestore` to manually restore the backup.

Conclusion

Checking and updating MongoDB on Windows is a simple process when done carefully. Always backup your data before attempting updates, and follow MongoDB’s best practices to avoid any issues. With the latest version of MongoDB installed, you can enjoy enhanced functionality and improved security for your databases.