[mongodb] mongorestore crashes
Yesterday I bought a Digital Ocean VPS with MongoDB preinstalled. I chose the cheapest one, which is $5 / month. With FileZilla, using the SFTP protocol, I uploaded a Mongo dump that I wanted to restore with the “mongorestore” command. Mongorestore terminated halfway and it also made the MongoDB server crash! WTF?
It turned out that mongorestore didn’t have enough memory, but it didn’t print an error message about it! It just stopped and said that the server is not running. Yeah, it was not running because it just crashed because of you, you dumb program…
So, the cheapest DO VPS has 512 MB RAM, which is not much for MongoDB. By default, this cheapest VPS has no swap at all. So the solution is the following: add a swap file. I created a swap file of size 2 GB (maybe 1 GB is also enough) and retried mongorestore. This time it was successful. During the import process I was checking “htop” and the swap file was used indeed.
How to create a swap file?
Check out this article: http://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/. It explains the process step by step.