How to check version and upgrade MongoDB on Mac

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

Introduction

MongoDB is a popular NoSQL document database that many developers use to manage data for their applications. If you are working with MongoDB on a Mac, it’s essential to keep your database version up to date to benefit from the latest features, bug fixes, and performance improvements. This tutorial will guide you through the process of checking the MongoDB version and upgrading to the latest release on macOS.

Checking MongoDB Version

To determine the version of MongoDB installed on your Mac, open your terminal and run the following command:

mongod --version

This outputs the version information of your MongoDB installation. Here’s an example of what you might see:

db version v4.4.6
Build Info: {
    "version": "4.4.6",
    "gitVersion": "f6e7b4d537c1b1baca4b875fbaf8b3c513c2e0f4",
    ... more info ...
}

Using Homebrew to Manage MongoDB

Homebrew is an excellent package manager for macOS that simplifies the installation and management of software packages like MongoDB. If you don’t have Homebrew installed, you can install it by running this command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once you have Homebrew installed, use the following command to add the MongoDB tap, which will enable you to install MongoDB via Homebrew:

brew tap mongodb/brew

Installing MongoDB

After adding the MongoDB tap, you can install MongoDB with Homebrew using the following command:

brew install mongodb-community

Starting and Stopping the MongoDB Service

Upon installation, MongoDB does not start automatically. You can start the MongoDB service by running the following command:

brew services start mongodb/brew/mongodb-community

To stop the service, use the command:

brew services stop mongodb/brew/mongodb-community

Upgrading MongoDB

To upgrade your MongoDB version via Homebrew, make sure all homebrew packages are up to date before proceeding:

brew update

After updating Homebrew, upgrade MongoDB with the following command:

brew upgrade mongodb-community

This will fetch the latest MongoDB version and upgrade your installation accordingly. After an upgrade, it is good practice to check the version again to verify the success of the process:

mongod --version

If a newer version of MongoDB is released that requires changes to MongoDB configuration files or if you need to update the storage engine, additional steps may need to be performed. Refer to the official MongoDB documentation for detailed instructions relating to those specific versions and changes.

Conclusion

Keeping MongoDB up to date on your Mac is a straightforward process with Homebrew, and it is a crucial aspect of database management. Always ensure that you back up your data before performing upgrades and check the MongoDB release notes for any specific migration steps that may be required for major version changes.