I recently made the mistake of executing the following commands while my MongoDB instance (version 6.0.19) was running via systemctl (the system is Ubuntu 20.04.6 LTS):
sudo dpkg -i --force-overwrite /var/cache/apt/archives/mongodb-org-server_6.0.19_amd64.deb
sudo dpkg -i --force-overwrite /var/cache/apt/archives/mongodb-org-mongos_6.0.19_amd64.deb
sudo dpkg -i --force-overwrite /var/cache/apt/archives/mongodb-database-tools_100.10.0_amd64.deb
After each one, I ran sudo apt -f install
. At the end, I ran sudo apt -f install
and sudo apt autoremove
. These commands crashed my mongodb instance and I tried to fix it by removing MongoDB from the system and reinstalling it. To remove, I used sudo apt-get purge, and manually removed the data directory /var/lib/mongodb and /var/log/mongodb directories. Before I erased /var/lib/mongodb I copied the folder to a backup directory, /var/lib/mongodb_backup_force.
Then, I reinstalled MongoDB following the instructions here. I accidentally installed the latest version 8.0.4, then uninstalled again and reinstalled the same version as I had previously, version 6.0.19. Running sudo systemctl start mongod
starts the service with no problems. However, after I stop, and copy the contents of /var/lib/mongodb_backup_force into /var/lib/mongodb, and restart the service, I get:
mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2024-12-24 20:51:26 EST; 12min ago
Docs: https://docs.mongodb.org/manual
Process: 29193 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=14)
Main PID: 29193 (code=exited, status=14)
Dec 24 20:51:26 rapid-1662.vm.duke.edu systemd[1]: Started MongoDB Database Server.
Dec 24 20:51:26 rapid-1662.vm.duke.edu mongod[29193]: {"t":{"$date":"2024-12-25T01:51:26.863Z"},"s":"I", "c":"CONTROL", "id":7484500, "ctx":"-","msg":"Environment variable MONGODB_CONFIG_OVERRIDE_NOFORK == 1, overriding \"processManagement.fork\" to false"}
Dec 24 20:51:26 rapid-1662.vm.duke.edu systemd[1]: mongod.service: Main process exited, code=exited, status=14/n/a
Dec 24 20:51:26 rapid-1662.vm.duke.edu systemd[1]: mongod.service: Failed with result 'exit-code'.
When I consult the logs, I see An incomplete repair has been detected! This is likely because a repair operation unexpectedly failed before completing. MongoDB will not start up again without --repair.
However, running mongod --repair
fails with: Failed to start up WiredTiger under any compatibility version. This may be due to an unsupported upgrade or downgrade.
Please help me restore the data. Thank you!