RSS Feed

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 .

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 -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 -d thedb -u -p .


Then teach the php app the new connection:

 $this->host = 'mongodb://';
 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 responses to “Migrate to Mongolab”

  1. Mike Hayes says:

    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 :)

  2. Ivo Bathke says:

    Sure, for development its recommended to use a local setup.

Leave a Reply

Your email address will not be published. Required fields are marked *