Fongo, Mongo, and Jongo Unchained

MongoDb is a really good database. For a test addict like me it had one small problem. You either had to install a local mongo or use a distant mongo for your tests.

The first option is good because it doesn’t rely on the network. But building a java project should be as simple as: Buy a new computer, open a terminal, git clone [repo], mvn clean install. Done. (I guess a windows computer doesn’t qualify here…)

The second option is bad because tests shouldn’t rely on external resources. It’s slow and error-prone.

Enters Fongo!

Fongo is an in-memory implementation of mongoDb. Not everything is implemented but it sufficient for most tests.

Here’s a test where I connect to an in-memory mongo, create and query documents. So simple!

To make it even easier to access mongo from Java code, I use Jongo. It rocks!

Notice also that to connect to a real mongo server, all I need is to change:

DB db = new Fongo("Test").getDB("Database");


DB db = new MongoClient(HOST).getDB("Database");

3 thoughts on “Fongo, Mongo, and Jongo Unchained”

    1. trop lent embedmongo, c’est ce que j’utilisais aussi à une époque
      je suis passé depuis quelques semaines à Fongo et je suis enfin efficace !

Comments are closed.