Search code examples
javamongodbmavenclojuremonger

CompilerException java.lang.ClassNotFoundException: org.bson.types while trying to connect to mongo with Monger


Trying to connect to Mongo using Monger and I get the following error

CompilerException java.lang.ClassNotFoundException: org.bson.types

I have added the dependency [com.novemberain/monger "3.1.0"] in project.clj and did a lein re-install and is trying to import bson.types as :import [org.bson.types ObjectId].

The monger dependency is reflecting in my auto generated pom.xml file as

<dependency>
<groupId>com.novemberain</groupId>
<artifactId>monger</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>

Am I missing any dependency or what am I doing wrong ? .


Solution

  • Looks like monger depends on org.mongodb:mongodb-driver, which does not include the bson parts of the mongo driver. So you'd also need to include the bson dep explicitly, which is org.mongodb:bson.

    Looks like they also publish a org.mongodb:mongodb-java-driver uberjar that includes the driver, bson, and other stuff in a single dep. If you added that you'd get everything (but you should probably exclude those deps pulled in by monger to avoid conflicts).