How to Uninstall MongoDB

Tahseen Tauseef Feb 02, 2024
  1. Uninstall MongoDB from Ubuntu Linux
  2. Uninstall MongoDB from MacOS
  3. Uninstall MongoDB from Windows
  4. MongoDB Atlas
How to Uninstall MongoDB

To remove MongoDB from your computer, you must first remove the MongoDB services, databases, and log files.

Using this MongoDB article, you will be able to uninstall MongoDB from Ubuntu Linux, Mac, and Windows. Make sure to keep a backup of your data, as once you uninstall, it cannot be reversed.

Every new version of MongoDB brings new features. MongoDB 5.0, for example, includes time-series collections, window functions, online archiving, and other features.

This is the perfect in-depth tutorial to help you uninstall your prior MongoDB version and get started with the latest versions if you plan to install a new version of MongoDB. We’ll also go through the MongoDB Atlas cluster, which offers a download-free alternative to using MongoDB.

This MongoDB article will discuss in detail how to uninstall MongoDB from:

  1. Ubuntu Linux
  2. Mac
  3. Windows

Uninstall MongoDB from Ubuntu Linux

Stop the daemon process and delete the MongoDB applications, configuration files, data files, and log files to uninstall MongoDB from Ubuntu Linux. All of this should be done from the terminal.

The user must have sudo access, i.e., a superuser. Log in as an admin and join the sudo group to gain sudo access.

Steps for Uninstalling MongoDB from Ubuntu Linux

To uninstall MongoDB, run the following commands one by one.

  1. Stop the MongoDB process.

    sudo service mongod stop
    
  2. Completely remove the installed MongoDB packages.

    sudo apt-get purge mongodb-org*
    
  3. Remove the data directories, MongoDB database(s), and log files.

    sudo rm -r /var/log/mongodb /var/lib/mongodb
    

To verify that MongoDB has been successfully uninstalled, type the command below.

service mongod status

If the user wishes to reinstall MongoDB on Linux, search the following links on your search engine below.

  1. Install MongoDB on Linux
  2. Install MongoDB Community Edition on Ubuntu
  3. Install MongoDB Community Edition on CentOS
  4. Install MongoDB Community Edition on Red Hat

You may also create a free MongoDB Atlas cluster to access the MongoDB database as a service without having to install/uninstall anything.

Uninstall MongoDB from MacOS

To remove any version of MongoDB from your macOS, follow the below steps on the terminal.

  1. Check if any mongo service is running.

    launchctl list | grep mongo
    
  2. If you had installed MongoDB using Homebrew, unload MongoDB.

    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
    rm -f ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
    launchctl remove homebrew.mxcl.mongodb-community
    
  3. Kill the mongod process if it exists.

    pkill -f mongod
    
  4. If you have installed MongoDB using brew, uninstall MongoDB with the below command.

    brew uninstall mongodb-community
    brew uninstall mongodb-database-tools
    brew uninstall mongosh
    brew untap mongodb/brew
    
  5. If you installed MongoDB manually (without Homebrew), then use:

    rm -rf <yourmongodb_folder>
    
  6. Remove database files.

    rm -rf /usr/local/var/mongodb
    

To check if MongoDB has been uninstalled properly, check if any MongoDB files are still present.

ls -al /usr/local/bin/mongo*
zsh: no match found: /usr/local/bin/mongo*

For installing a newer MongoDB version, search for Install MongoDB on macOS on your search engine. Alternatively, avoid the need for installing/uninstalling in the future by trying MongoDB Atlas.

Uninstall MongoDB from Windows

The user can uninstall MongoDB from Windows using any of the following options.

Uninstall MongoDB using Apps and Features

  1. Open the Windows Start menu and look for Apps and Features system settings.
  2. Select the MongoDB application from the list of applications displayed. You can also look for MongoDB in the list.
  3. Click on the MongoDB app name to uninstall.

Uninstall MongoDB using Control Panel (Windows 10)

  1. Using the Start menu or a command prompt, go to Control Panel (control command).
  2. When the Control Panel is open, go to the Programs/Programs and Features section and select Uninstall a program.
  3. Select and right-click on MongoDB.
  4. Click Uninstall.
  5. The user will be asked to confirm the uninstall by Windows. Select Yes.

Regardless of how you remove MongoDB on Windows, you must restart your computer for the changes to take effect.

The official MongoDB documentation website has instructions for reinstalling MongoDB on Windows. Alternatively, consider MongoDB Atlas to avoid future installation/uninstallation requirements.

MongoDB Atlas

Besides the fact that you don’t have to install or uninstall the MongoDB database on your machine, there are several benefits to utilizing MongoDB Atlas.

MongoDB Atlas is a cloud-based database with several features, including built-in security and automated backups.