DEV Community

Nadine M. Thêry
Nadine M. Thêry

Posted on

MongoDB deletes my db after unclean shutdown?

Hey guys!

I am just starting with MongoDB and It has happened something really weird. I didn't lose anything valuable. But I definitely need to know what happened in order to avoid it to happen again, when I DO have something important.

I had created 2 small databases and had also shut down and restarted mongod several times. No problem.

However, I accidentally quit Hyper (bash) without closing the server. So I went back to bash, and killed the task with the following line with admin permission:

$ taskkill //PID 3628 //F

It finished the process. And then I was able to restart the mongo server and keep working. But when I did all the databases were gone!

So, it looks to me like pretty obvious that it was due to the unclean shutdown, but cannot find anything documented about it. Except for this short line in the Mongo Documentation:

"In a clean shutdown a mongod completes all pending operations, flushes all data to data files, and closes all data files. Other shutdowns are unclean and can compromise the validity of the data files."

Just wondering if any of you have ever experienced this, and just to confirm that this actually happened to me because I killed the process from the console or if you think there might be another reason.

Thank a lot!

P/S: working with NodeJS, Hyper (gitbash), MongoDB last ver., local.

Latest comments (8)

Collapse
 
ashraflobo profile image
Ashraf Lobo

Hey, I also experienced this unintentional deletion of collections. In my case, it has happed twice, but only happens when I'm working using the mongo shell. Usually, I use MongoDB Compass, but on some rare occasions, I have to fire up the shell. On two separate occasions, I have lost collections without being able to recover them. On the first one, I just started the mongo shell and all my collections, including others from different projects got deleted. On the second occurrence, I used mongo shell to stop my MongoDB server and the collection for the project I was currently working on got deleted. Could this also be considered an unclean shutdown?

PS: I haven't changed my data folder. It's still the same one I started with when I installed MongoDB.

 
nestedsoftware profile image
Nested Software • Edited

@artemix I think you could develop this a bit and it would make for a good standalone article!

Thread Thread
 
nanythery profile image
Nadine M. Thêry

Thanks a lot for sharing knowledge and the time you spent in this answer. I will definitely think about it.

Collapse
 
nanythery profile image
Nadine M. Thêry

I will keep that in mind. I am not seriously working on any project, just learning apps, so I follow the path of the course from Angela Yu.

I have more experience with SQL and they certainly seem more reliable and solid nowadays. However, I do think that the choice should be also made considering the complexity of the app and its components. Even though you can use an SQL DB, I don't know If I would like to use it for a Blog, for instance. What do you think?

Collapse
 
nestedsoftware profile image
Nested Software

Did you restart mongodb with the --repair option? Someone with more experience will hopefully chime in, but that could be the issue...

Collapse
 
nanythery profile image
Nadine M. Thêry

I first restarted it normally, since there were no errors. And all the dbs were gone already.

Then launched a --repair, but remained the same :S

Collapse
 
nestedsoftware profile image
Nested Software

Can you check the logs to see if anything suspicious is showing up there?

Also, this stackoverflow answer suggests mongo may have been restarted pointing to a different directory for its database files, so that would be another thing to check.

Lastly, I did some searching and found a few mentions of problems that seemed similar to yours related to the version of mongodb being used, so check to see if you're using an older version as well.

Thread Thread
 
nanythery profile image
Nadine M. Thêry

I will keep on searching to see if I find those DBs, so strange.

Thanks a lot for your help and effort.