To completely remove MongoDB, you have to remove the MongoDB services, MongoDB packages, the databases, and any log files. Using this guide, you will be able to uninstall MongoDB from Linux, Mac, and Windows. The basic uninstallation process is the same, with some variations in the commands depending on the operating system. Remember to keep a backup of your data, as the uninstall cannot be reversed.
Every new version of MongoDB comes with a host of new features and benefits. For example, MongoDB 7.0, the latest stable version, comes with advanced features for Atlas Search Index management, and several improvements in performance, security, migrations, developer experience, and much more. If you are planning to install a new version of MongoDB, this is the perfect in-depth guide to help you completely uninstall MongoDB (older version) and get started with the new versions.
Table of contents
To uninstall MongoDB from Linux, you have to stop the daemon process, and remove the MongoDB applications, configuration files, data files, and MongoDB log files. All of this should be done from the terminal.
You must have sudo access, i.e., a superuser. To get sudo access, log in as an admin and add yourself to the sudo group
Type the following commands one by one to uninstall MongoDB:
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb /var/lib/mongodb
service mongod status
If you wish to reinstall MongoDB on Linux, follow the links below:
Alternatively, you can spin a free MongoDB Atlas cluster to access the MongoDB database as a service, thus avoiding the need for install/uninstall.
For uninstalling MongoDB from Mac, follow the below steps on the terminal:
launchctl list | grep mongo
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
rm -f ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
launchctl remove homebrew.mxcl.mongodb-community
pkill -f mongod
brew uninstall mongodb-community
brew uninstall mongodb-database-tools
brew uninstall mongosh
brew untap mongodb/brew
rm -rf <yourmongodb_folder>
Remove database files:
rm -rf /usr/local/var/mongodb
To check if the uninstall was properly done, check if any MongoDB files are still present:
ls -al /usr/local/bin/mongo*
zsh: no matches found: /usr/local/bin/mongo*
To install a newer MongoDB version, visit Install MongoDB on Mac. Alternatively, avoid the need for install/uninstall in the future by trying free today.
For uninstalling MongoDB from Windows, use any of the following options.
3. Select and right click on MongoDB.
Whichever way you use for uninstalling MongoDB on Windows, make sure to restart your machine for the changes to reflect. You can reinstall MongoDB on Windows from the official MongoDB documentation page. Alternatively, avoid the need to install/uninstall in the future by trying MongoDB Atlas for free.
There are many reasons why you should use MongoDB Atlas, other than the fact that you don't have to install/uninstall a MongoDB database on your machine. MongoDB Atlas runs on the cloud and provides a host of features, including built-in security and automated backups. Try a free cluster today to explore the benefits.
Once you install MongoDB on Mac using HomeBrew, you can find MongoDB-related files in the following locations:
MongoDB binaries:
/usr/local/Cellar/mongodb-community/[version]/bin/usr/local/Cellar/mongodb-community/[version]/bin
Logs:
/usr/local/var/log/mongodb/
mongod.conf file:
/usr/local/etc/mongod.conf/usr/local/etc/mongod.conf
MongoDB databases:
/usr/local/var/mongodb/data/db/usr/local/var/mongodb/data/db