1 min read

Monglorious: Java Edition

Previously introduced, Monglorious is the MongoDB client library I created to execute string queries, as opposed to using a DSL library created in your language of choice. Monglorious is written in Clojure, which is a great language for parsing text and interpreting it. It's not the most popular, but it does run on the JVM so interop with Java and other JVM languages is possible.

However, I've found the Clojure-using-Java interop to be much smoother than the reverse, Java-using-Clojure. This is largely due to the dynamic type system in Clojure, which leads to a lot of type casting on the Java side.

All this to say, I decided to write a Java library to wrap Monglorious, so I could provide a more idiomatic interface and hide the Clojure interop details. And thus monglorious-java was born.

Here's an example:

try (MongloriousClient monglorious = new MongloriousClient("mongodb://localhost:27017/testdb")) {
    long actual = monglorious.execute("db.documents.count()", Long.class);

To use, just download the JAR attached to the most recent release. Then add it to your project and import the main class:

import org.baumandm.monglorious.java.MongloriousClient;

It is being released an überjar containing an AOT'd version of Monglorious, so that any downstream users don't have to add a Clojure AOT step to their build workflows. It's not ideal, but it should be simpler for everyone else who wants to use it.

You can find the code here, and more information about Monglorious here.