Migrate to Mongolab

Recently i ran into RAM troubles on my vserver for some reasons, i encountered the evil:

Cannot allocate memory at ...

So first i suspected mongodb to use up loads of memory as top showed.

But after some recherche work i learned mongodb only -seems- to use a lot of memory.
see here and here and here
The actual usage was around 20mb RAM, so mongodb was innocent.

The true RAM monsters were some apache and php-fpm zombies, but thats another story.

While suspecting mongodb i thought about outsourcing the mongodb and i found a free and sufficient offer in mongolab.
My interests were on and i gave it a try.
The free version has a limit for up to 240MB storage and since my app is just a small counter it should last for some time.

The registration was easy, creation of the database aswell and the administration panel is also pretty cool and informative.

Then create a user and migrate:

First get my data from the vserver on the vserver:

 mongodump --host

Then fetch it to my local machine:

 scp -r me@vserver.de:/var/www/vhosts/verrueckte/dump/mongodumpdata .

Ups i didnt had no mongo client on my local machine, go get it:

 sudo apt-get install mongodb-clients

Now connect to the mongolab via your console

 mongo db123xyz.mongolab.com:12345/thedb -u <user> -p <pw>

Hey works, great!
Alright see you later.

 > exit;

Now import the dumps to continue the counter there were i stopped.

 cd mongodumpdata
 mongorestore -h db123xyz.mongolab.com:12345 -d thedb -u -p .


Then teach the php app the new connection:

 $this->host = 'mongodb://user:pw@db123xyz.mongolab.com:12345/thedb';
 new mongo($this->host);

There you go! The counter is storing its stuff to the mongolab database.
And i can stop the mongod on my machine and free some memory.

 ps aux | grep mongodb
 kill <PID>

2 Replies to “Migrate to Mongolab”

  1. Good post. All well and good until your connection drops, which doesn’t usually happen for me but when it does I like to know that I can continue coding / developing in the mean time :)

Comments are closed.