Sling Academy
Home/MongoDB/How to completely remove MongoDB from Windows

How to completely remove MongoDB from Windows

Last updated: February 01, 2024

Introduction

Uninstalling MongoDB from your Windows machine is a task that you might want to undertake if you no longer need the database or if you’re looking to do a clean installation. MongoDB comes with a set of binaries that are installed in your system and might have created several data and log directories which are not removed during a standard uninstall process. This comprehensive guide explains how to completely remove MongoDB from your Windows environment.

The Steps

Step 1: Stop MongoDB Service

Before uninstalling MongoDB, you must stop any running MongoDB service. You can do this using the Windows Services Manager or through the Command Prompt.

sc stop MongoDB

This command sends a stop command to the MongoDB service. If it was successful, you will get a SUCCESS message.

Step 2: Uninstall MongoDB

Once the service is stopped, you can proceed to uninstall MongoDB from your system via the control panel or by using commands.

msiexec /x  /qb

If you installed MongoDB using the MSI installer, you need to provide the original ‘.msi’ file path. Running this command will initiate the uninstall process.

Step 3: Remove MongoDB Directory

After successfully uninstalling MongoDB, the next step is to remove any remaining MongoDB directories.

rmdir /s /q C:\Program Files\MongoDB

This command will remove the MongoDB directory from the Program Files along with all its contents.

Step 4: Delete Data and Log Directories

By default, MongoDB data and log directories are located in C:\data\db and C:\data\log respectively. You need to manually remove them.

rmdir /s /q C:\data\db
rmdir /s /q C:\data\log

These commands will remove the default data and log directories recursively.

Step 5: Remove MongoDB from the System Path

The MongoDB executables are usually added to the system PATH to run from the command line. You must remove the MongoDB path manually.

[System.Environment]::SetEnvironmentVariable("PATH",([System.Environment]::GetEnvironmentVariable("PATH","Machine") -replace "C:\Program Files\MongoDB\Server\4.4\bin;"),[System.EnvironmentVariableTarget]::Machine)

This PowerShell command removes the MongoDB path from the system PATH variable for all users.

Step 6: Remove MongoDB from Windows Registry

The Windows registry may contain MongoDB references that need to be cleaned out. Caution is advised when editing the registry.

reg delete "HKLM\SOFTWARE\MongoDB" /f

This command line will delete the MongoDB entry from Windows registry.

Step 7: Uninstall MongoDB Compass (Optional)

If you installed MongoDB Compass, the graphical interface for MongoDB, you might also want to uninstall it.

msiexec /x  /qb

Similar to MongoDB, you need to provide the path to the ‘msi’ file to uninstall Compass.

Conclusion

Successfully removing MongoDB involves not just uninstalling the software, but also removing service details, directories, system paths, and registry entries. Following the steps outlined in this guide ensures that MongoDB is completely removed from your system, allowing for a fresh installation if necessary.

Next Article: How to completely uninstall MongoDB from Mac

Previous Article: An Introduction to NoSQL and MongoDB for Beginners

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)