Sling Academy
Home/MongoDB/How to check version and update MongoDB on Windows

How to check version and update MongoDB on Windows

Last updated: February 01, 2024

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.

Next Article: How to check version and upgrade MongoDB on Mac

Previous Article: 3 ways to self-host MongoDB on Ubuntu

Series: MongoDB Tutorials

MongoDB

You May Also Like

  • MongoDB: How to combine data from 2 collections into one
  • Hashed Indexes in MongoDB: A Practical Guide
  • Partitioning and Sharding in MongoDB: A Practical Guide (with Examples)
  • Geospatial Indexes in MongoDB: How to Speed Up Geospatial Queries
  • Understanding Partial Indexes in MongoDB
  • Exploring Sparse Indexes in MongoDB (with Examples)
  • Using Wildcard Indexes in MongoDB: An In-Depth Guide
  • Matching binary values in MongoDB: A practical guide (with examples)
  • Understanding $slice operator in MongoDB (with examples)
  • Caching in MongoDB: A practical guide (with examples)
  • CannotReuseObject Error: Attempted illegal reuse of a Mongo object in the same process space
  • How to perform cascade deletion in MongoDB (with examples)
  • MongoDB: Using $not and $nor operators to negate a query
  • MongoDB: Find SUM/MIN/MAX/AVG of each group in a collection
  • References (Manual Linking) in MongoDB: A Developer’s Guide (with Examples)
  • MongoDB: How to see all fields in a collection (with examples)
  • Type checking in MongoDB: A practical guide (with examples)
  • How to query an array of subdocuments in MongoDB (with examples)
  • MongoDB: How to compare 2 documents (with examples)