Exception while migrating to latest Java Driver

I’m trying to migrate from old “uber-jar” mongo-java-driver to new mongodb-driver-sync. When I use version 4.0.5 it works perfectly without code changes. When I try to use 4.1.1 or 4.2.0 - getting exception:
org.bson.codecs.configuration.CodecConfigurationException: Can’t find a codec for interface java.util.List
I’ve tried to use corresponding version of mongodb-driver-legacy - same result.

Is it known issue ? Is there a way to use latest driver ?

Hello @Alex_Rubin, welcome to the MongoDB Community forum.

Is there a way to use latest driver ?

See the Java Driver 4.1 Installation in the documentation.

Please post the code which is throwing the exception and also tell about the MongoDB server version.

It is not a issue with specific Java code. It’s issue with specific driver version.

Hi Alex,

That doesn’t sound right, if you could post an example reproducing the issue we should be able to help identify the cause. I can’t think of anything in the change log from 4.1.x that would cause that issue.

Ross

1 Like

Hi, Lawley. Here is code snapshot:

MongoCollection <Document> collection;

Document document = new Document();

document.put("_id", id_value);
document.put(“value1”, value1);
document.put(“value2”, value2);
document.append(“date”, new Date());
collection.insertOne(document); // Throws exception

Hello @Alex_Rubin, I tried the following code with Java Drivers 4.0.5, 4.1.1 and 4.2.0. The code runs just fine. I didn’t know what the variable values are for id_value, value1 and value2 in your code, so substituted the values with my own. It will help if you can provide those too.

try(MongoClient client = MongoClients.create()) {
    MongoCollection<Document> collection = client.getDatabase("testdb")
                                                 .getCollection("testcoll");
    Document document = new Document();
    document.put("_id", 1);
    document.put("value1", "John Doe");
    document.put("value2", "New York");
    document.append("date", new Date());
    collection.insertOne(document);
}

Taking @Prasad_Saya example and using a list also works as expected.

Here is an example github project that runs the shown code but with a list value.

Rpss

1 Like