Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

How to Completely Remove MongoDB from an Ubuntu Server

Learn the safe order for completely removing MongoDB from Ubuntu, including backups, edition-specific purge commands, custom dbPath and log paths, directory deletion, and verification.
Length8 min Posted Quest giverVGSources Team

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To completely remove MongoDB from an Ubuntu server, stop the mongod service, purge the correct MongoDB package family, then delete the configured database and log directories. The final deletion removes every database and is irreversible without a backup, so read /etc/mongod.conf and preserve anything you may need before running destructive commands.

What “completely remove MongoDB” includes

An Ubuntu package removal is not necessarily a complete uninstall. A full removal has three separate parts:

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Applications: the MongoDB server and related packages.
  • Configuration: package-managed configuration files, including the MongoDB configuration removed by a purge.
  • Persistent files: the database files and log files stored in the configured directories.

MongoDB’s official Community Edition instructions describe the operation this way: “This process will completely remove MongoDB, its configuration, and all databases. This process is not reversible, so ensure that all of your configuration and data is backed up.” Treat the database-directory step as a data-destruction operation, not as routine package maintenance.

Before you run a destructive command

Confirm that deleting the databases is really your goal

If you only need to replace MongoDB, troubleshoot a service, or reclaim package space while preserving data, do not continue to the directory-deletion step. The complete-removal procedure intentionally deletes the databases. A backup is the only way to recover those files after removal.

#1 Best Overall
Sale
Western Digital 8TB My Book Desktop External Hard Drive, USB 3.0, External HDD with Password Protection and Backup Software - WDBBGB0080HBK-NESN
  • Massive capacity, up to 22TB capacity. (1TB = one trillion bytes. Actual user capacity may be less depending on operating environment.).Specific uses: Personal
  • Includes software for device management and backup with password protection (Download and installation required. Terms and conditions apply. User account registration may be required.)
  • 256-bit AES hardware encryption
  • SuperSpeed USB (5 Gbps); USB 2.0 compatible
  • Trusted storage built with WD reliability

Back up data and configuration

Export the databases using the backup method appropriate to your environment and retain any settings you will need later. At minimum, preserve a copy of /etc/mongod.conf before deleting packages or files. An external hard drive can be used as optional physical backup storage; it is not required for the uninstall itself. Confirm that the backup can be read before proceeding, because the removal cannot be undone by reinstalling MongoDB.

Identify the MongoDB edition and package family

The package glob must match the edition installed on the server. Community Edition uses the mongodb-org family. Enterprise Edition uses mongodb-enterprise. Do not use the Community glob on an Enterprise installation and assume it removed everything; choose the family shown by the packages installed on your server.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Installation Purge command Packages targeted
MongoDB Community Edition sudo apt-get purge mongodb-org* The mongodb-org package family and its configuration files
MongoDB Enterprise Edition sudo apt-get purge mongodb-enterprise* The mongodb-enterprise package family and its configuration files

Understand the paths that will be deleted

The default Enterprise Ubuntu documentation identifies /var/lib/mongodb as the database path and /var/log/mongodb as the log path. Those are defaults, not guarantees. MongoDB can be configured to use different locations through the storage.dbPath and systemLog.path settings.

Read /etc/mongod.conf first

Open the configuration file while MongoDB is still installed, or use the copy you made during backup. Find the values for:

  • storage.dbPath, which identifies where database files reside.
  • systemLog.path, which identifies where MongoDB writes its log.

Record those paths before deleting anything. If either setting points away from the defaults, the default-directory commands will not remove the customized location. Conversely, deleting a directory merely because its name looks familiar can destroy unrelated data if the server was configured differently.

Configuration setting Default path documented for Ubuntu What to verify
storage.dbPath /var/lib/mongodb Whether the running installation actually stores databases there
systemLog.path /var/log/mongodb Whether logs are written there or to a custom location

Step 1: Stop MongoDB before changing files

Stop the daemon before purging packages or removing its data and log directories. On an Ubuntu system using systemd, run:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
  • Slim durable design to help take your important files with you
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption
  • 3-year limited warranty
sudo systemctl stop mongod

The official uninstall procedure also documents the service-compatibility command:

sudo service mongod stop

Use the command style supported by the server. Do not delete live database files while mongod is still running. Stopping the service first prevents the process from continuing to use files you are about to remove and gives you a definite point at which the daemon should no longer be writing logs.

Check that the stop request took effect

If you used systemd, inspect the service state before continuing:

sudo systemctl status mongod

If you used the compatibility interface, the documented verification form is:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
service mongod status

The important result is that MongoDB is no longer running. If the service remains active, stop it again using the interface available on that server and resolve that state before touching the data directory.

Step 2: Purge the installed package family

apt remove is not the complete-removal operation described by MongoDB. A normal remove can leave configuration behind. Use apt-get purge with the package family that matches your edition.

Rank #3
Sale
Western Digital 6TB My Book Desktop External Hard Drive, USB 3.0, External HDD with Password Protection and Auto Backup Software - WDBBGB0060HBK-NESN
  • Massive capacity, up to 18TB capacity (1 1TB = one trillion bytes. Actual user capacity may be less depending on operating environment.).Specific uses: Business, personal
  • Includes software for device management and backup with password protection (Download and installation required. Terms and conditions apply. User account registration may be required.)
  • 256-bit AES hardware encryption
  • SuperSpeed USB (5 Gbps); USB 2.0 compatible

Community Edition

For a Community Edition installation, run:

sudo apt-get purge mongodb-org*

The wildcard selects the Community package family, and the purge operation removes the packages together with their package-managed configuration files. Review the packages that the package manager proposes before accepting the transaction; the command should correspond to the Community installation you identified earlier.

Enterprise Edition

For an Enterprise Edition installation, run:

sudo apt-get purge mongodb-enterprise*

This is a different family from Community Edition. Selecting the wrong glob can leave the actual server packages installed, so confirm the edition and package names first.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why purging is different from removing

The distinction matters when the goal is a clean reinstallation or a server with no MongoDB configuration left. The official complete procedure uses purge specifically to remove the relevant package family and its configuration files. Purging does not, by itself, guarantee that database files and logs have disappeared; those directories are handled separately in the next step.

Step 3: Delete the database and log directories

Only perform this step after you have confirmed the backup and checked the paths in /etc/mongod.conf. These commands remove the default locations:

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb

The first command removes the default MongoDB log directory. The second removes the default database directory, including the databases stored there. There is no recovery option in these commands: once the files are deleted, a future MongoDB installation cannot recreate their contents.

When the defaults are not the active paths

If storage.dbPath points to a custom directory, remove that configured database directory instead of, or in addition to, /var/lib/mongodb—but only after confirming it contains the MongoDB data you intend to destroy. Apply the same rule to systemLog.path and /var/log/mongodb. Do not substitute the default paths blindly when the configuration specifies another location.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
WD 6TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBR9S0060BBK-WESN
  • World’s First 6TB 2.5” Portable Hard Drive
  • Slim durable design to help take your important files with you
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption

A customized deployment may also have more than one path worth reviewing if its configuration was changed over time. The safe sequence is to record every active database and log location, verify the backup, stop mongod, purge the package family, and then remove only the confirmed MongoDB directories.

Step 4: Verify that the server is gone

Check the service state

After purging and deleting the directories, run the documented status check:

service mongod status

On a systemd installation, you can also use:

sudo systemctl status mongod

The check is useful for distinguishing a removed service from a daemon that is still present but stopped. If the status command still identifies an installed mongod service, revisit the package-family choice and confirm that you purged the edition actually installed.

Inspect packages and configuration paths

Review the packages reported by the system’s package manager and compare them with the edition-specific family you selected. Also revisit the recorded values from /etc/mongod.conf, if that file still exists, and check every custom database and log location you identified. A default-directory deletion is not proof of complete removal when the configuration used custom paths.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the filesystem locations

Confirm that the default directories no longer contain MongoDB data when they were the active paths. For a customized installation, perform the same check against the configured locations. Keep the verification tied to the paths you recorded; searching for similarly named directories without confirming ownership can lead to deleting unrelated application data.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common situations that make an uninstall look incomplete

“I ran apt remove, but configuration remains”

This is expected when only the remove operation was used. The complete procedure calls for sudo apt-get purge and the correct package glob. Stop the service first, identify Community versus Enterprise, and run the matching purge command.

Best Value
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
  • Slim durable design to help take your important files with you
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • Back up smarter with included device management software[2] with defense against ransomware
  • Help secure your important files with password protection and hardware encryption
  • 3-year limited warranty

“The mongod service is still present”

A remaining service entry can mean the package family was not purged, the wrong edition glob was used, or the status check is being run through a compatibility interface that is reporting an installed service. Check the package family and repeat the matching purge after stopping the daemon. Do not delete directories while an active service still points to them.

“The default directories are empty, but disk space is still used”

Review storage.dbPath and systemLog.path in the saved or original configuration. MongoDB supports customized database and log paths, so data may be outside /var/lib/mongodb and logs outside /var/log/mongodb. Remove a custom location only after verifying that it is the MongoDB location covered by your backup and that it does not contain another application’s files.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

“The stop command does not work”

Try the other documented service interface: sudo systemctl stop mongod on systemd systems or sudo service mongod stop through the compatibility interface. Then check status again. The package and directory steps belong after the daemon has stopped.

“I need the data later”

Stop before running either rm -r command. The official warning is explicit that complete removal is not reversible. Make and validate a backup, preserve the configuration you need, and only then decide whether deleting the database and log directories is appropriate.

Complete-removal checklist

  • Database exports or another usable backup are stored safely.
  • A copy of /etc/mongod.conf and any required settings has been preserved.
  • The installation has been identified as Community (mongodb-org) or Enterprise (mongodb-enterprise).
  • storage.dbPath and systemLog.path have been read and recorded.
  • The mongod service has been stopped with systemctl or service.
  • The matching package family has been purged with apt-get purge.
  • The active database and log directories—not merely assumed defaults—have been removed.
  • service mongod status or systemctl status mongod has been checked after removal.
  • Installed packages and all recorded paths have been reviewed for leftovers.

The safe order, in one view

  1. Back up databases and configuration.
  2. Read /etc/mongod.conf and record the active database and log paths.
  3. Stop MongoDB with sudo systemctl stop mongod or sudo service mongod stop.
  4. Purge mongodb-org* for Community Edition or mongodb-enterprise* for Enterprise Edition.
  5. Delete the confirmed database and log directories, using the defaults only when they are the configured paths.
  6. Check service status and inspect packages and recorded paths for anything remaining.

Following that order removes the server software, package configuration, databases, and logs without confusing a package-only uninstall with complete MongoDB removal.

Quick Recap

SaleBestseller No. 1
Western Digital 8TB My Book Desktop External Hard Drive, USB 3.0, External HDD with Password Protection and Backup Software - WDBBGB0080HBK-NESN
Western Digital 8TB My Book Desktop External Hard Drive, USB 3.0, External HDD with Password Protection and Backup Software - WDBBGB0080HBK-NESN
256-bit AES hardware encryption; SuperSpeed USB (5 Gbps); USB 2.0 compatible; Trusted storage built with WD reliability
$329.99
Bestseller No. 2
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
WD 2TB My Passport, Portable External Hard Drive, Black, backup software with defense against ransomware, and password protection, USB 3.1/USB 3.0 compatible - WDBYVG0020BBK-WESN
Slim durable design to help take your important files with you; Help secure your important files with password protection and hardware encryption
$132.10
SaleBestseller No. 3
SaleBestseller No. 4
WD 6TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBR9S0060BBK-WESN
WD 6TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBR9S0060BBK-WESN
World’s First 6TB 2.5” Portable Hard Drive; Slim durable design to help take your important files with you
$259.00
Bestseller No. 5
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
WD 4TB My Passport, Portable External Hard Drive, Black, Backup Software with Defense Against ransomware, and Password Protection, USB 3.1/USB 3.0 Compatible - WDBPKJ0040BBK-WESN
Slim durable design to help take your important files with you; Help secure your important files with password protection and hardware encryption
$181.00

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.