Every new version of MongoDB comes with a host of new benefits. For example, MongoDB 5.0 comes with time-series collections, window functions, online archiving, and much more. If you are planning to install a new version of MongoDB, this is the perfect in-depth guide to help you uninstall your previous MongoDB version and get started with the new versions. We also introduce the MongoDB Atlas cluster, which provides an alternate download-free approach to use MongoDB.
Jump to Instructions for:
To uninstall MongoDB from Linux, you have to stop the daemon process, and remove the MongoDB applications, configuration files, data files, and 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:
Stop MongoDB process:
sudo service mongod stop
Completely remove the installed MongoDB packages:
sudo apt-get purge mongodb-org*
Remove the data directories, MongoDB database(s), and log files:
sudo rm -r /var/log/mongodb /var/lib/mongodb
To check if MongoDB is successfully uninstalled, type:
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.
To completely delete any version of MongoDB from Mac, follow the below steps on the terminal:
Check if any mongo service is running:
launchctl list | grep mongo
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
Kill the mongod process, if it exists:
pkill -f mongod
If you had 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
If you installed MongoDB manually (without Homebrew), then use:
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 MongoDB Atlas free today.
You can uninstall MongoDB from Windows using any of the following options.
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 for install/uninstall in the future by trying MongoDB Atlas free today.
There are many reasons why you should use MongoDB Atlas, other than the fact that you don’t have to install/uninstall 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
Logs:
/usr/local/var/log/mongodb/
mongod.conf file:
/usr/local/etc/mongod.conf
MongoDB databases:
/usr/local/var/mongodb/data/db