If you encounter some problems with your MongoDB server and try to reinstall it or just want to uninstall it. The following will cover how to purge Mongo completely (including dependencies, configuration file, logs and database storage) on Debian/Ubuntu-based Linux distros (e.g. Linux Mint, Pop!_OS, Elementary OS).
Stop the MongoDB daemon (
mongod.service) so no more data will be written to the disk:
sudo systemctl stop mongod
Uninstall MongoDB server and its related packages (tools, client, etc.) from your system:
sudo apt purge mongodb*
Remove the unused dependencies:
sudo apt autoremove
Although MongoDB is now uninstalled, there are still some files left to clean.
Remove the configuration file (
sudo rm -f /etc/mongod.conf
Remove the logs in
sudo rm -rf /var/log/mongodb
Remove the database storage in
/data/db (default value of MongoDB's
sudo rm -rf /data/db