Fixing “Unexpected mongo exit code null. Restarting” Error

I was getting this “Unexpected mongo exit code null. Restarting” error yesterday out of the blue. Forum searches here showed that this can be a tough bug to fix.

I decided that this looked like a local mongo database corruption error.

I think I know how it might have happened. A few days ago, I was doing some major upgrades to local NPM packages. To be safe I first compressed my entire project folder into a zip package, so it would be fast and easy to go back to, and continued. I did this several times and I think there were a couple of times when I left my IDE open and possibly even running. It may have thought it was writing to database A when really it had been switched to database B – corrupting database B. Otherwise I really can’t imagine how it could have happened. So I got done working on the NPM package updates that way.

A couple days later, I got the “Unexpected mongo exit code null. Restarting” Error. I restored from time machine backup to the previous night when I know everything had been working fine. But the corruption error was still there.

So then I restored from a time machine backup from 2 days ago. The db corruption error was still there! Baffling.

So then I restored from a time machine backup from 2 weeks ago. This time the database was fine. I restored my latest code changes from remote git repo. And that took care of it.

I have an off-site backup but that is only for the most recent version of each data file. If that’s all I’d had, I would have been in some trouble. I would have to wipe my local mongo db, and restore from my most recent dump of it, which was a year old.

So this shows, I think, the great importance of having some sort of local or offsite backup that keeps individual backups going back for weeks or months.

All is working now.

2 Likes

Yes, don’t trust the local database at all. What we find works best is a redacted import from production. Can be a full copy or a limited one. We just have some custom script for that reducing the amounts of records, filtering out private info etc.

2 Likes