Announcing Test::mongod

After having done a couple of projects with MongoDB and working on and off on a personal project, I found myself wanting something like Test::mysqld, but alas it did not exist on CPAN. So here it is Test::mongod. It's rough but will get you a throw away instance of MongoDB in a /tmp directory that will be cleaned up when the script ends. The code can also be found on GitHub.

use Test::mongod;


my $mongod = Test::mongod->new;  # get a temp db on a random port.
my $port = $mongod->port; # get the port to feed to your client app.

Be aware that depending on your hardware, this will block till the server is listening and ready to receive queries - which could be instant or take several seconds. To monitor startup get the db path and then tail the log file in another terminal.

diag $mongo->dbpath

Now to make some sort of fixture loader. Hmmm... what should it be call?

1 Comment

Very cool! I can think of some good uses for this.

Leave a comment

About Jesse Shy

user-pic Perl pays for my travel addiction.