Steps 👇🏽👇🏽👇🏽
Before uninstalling MongoDB ensure that the MongoDB service is stopped if it is currently running. You can achieve this by executing the command:
sudo systemctl stop mongod
remove the MongoDB packages by utilizing the package manager (apt):
sudo apt remove mongodb-org mongodb-org-server mongodb-org-shell mongodb-org-mongos mongodb-org-tools
Now, go ahead to remove any remaining configuration files and dependencies. Use the apt purge command to remove the MongoDB packages:
sudo apt purge mongodb-org
sudo apt purge mongodb-clients mongodb-org-database mongodb-org-server
sudo apt purge mongodb-database-tools
If you want to completely remove all data and log files associated with MongoDB, you can remove the MongoDB data directory:
sudo rm -r /var/lib/mongodb
_-Be cautious with this step, as it will permanently delete your MongoDB data.
_
You can also remove the MongoDB user and group if you no longer need them, This is an optional step, if you decide to make use these elements:
sudo deluser mongodb
sudo delgroup mongodb
Remove any remaining MongoDB configuration files:
sudo rm /etc/mongod.conf
Take out any MongoDB ordinary commands and shell scripts:
cd /usr/bin
rm -r mongo*
ls

Cleanup your dependencies by updating the package list and remove any leftover packages that were dependencies of MongoDB:
sudo apt autoremove
Confirm that MongoDB has been removed:
dpkg -l | grep mongodb