Migrating from mongo-java-driver 3.12.8 to java-sync 5.1

I am trying to migrate my Java Servlet application from the old java driver v3.12.8 to the new java-sync 5.1 driver. Everything works fine when connecting from the JRE. The database responds well and I can work with it when executing “normal java code” in the JVM.

The issue arises when I try to connect to my Servlet Website (WAR built with Maven and deployed on tomcat), I am not using any “fancy” framework like spring or similar (plain old JDK with Servlets and JSP as front-end). I have a listener for listening to whenever the server is started and stopped (to perform startup/shutdown tasks, like connecting/disconnecting from the DB) which logs the startup and shutdown routine execution in a collection.

Whenever I try to launch the application I get the following exception:

java.lang.NoSuchMethodError: 'com.mongodb.client.result.InsertOneResult com.mongodb.client.MongoCollection.insertOne(java.lang.Object)'

What I am trying to accomplish is inserting a new ‘Log’ document into the ‘Log’ collection, I am using the AutomaticPojoCodec implementation and I am using the Annotation convention for specifying the properties I want to store (and their names).

The application works fine with the old driver, but I cannot seem to be able to upgrade to the new version. Bear in mind that from the command line everything works fine, so I am really at my wits’ end.

Thanks in advance for any help!

There was a binary breaking change in 4.0 to the insertOne method. It previously returned void, and in 4.0 it was changed to return an InsertOneResult.

Make sure you recompile your application from source and don’t just drop in the 5.1 jar files after compiling against 3.12.8. Otherwise, linking will fail in the way that you describe above.

Regards,
Jeff