0

I'm using MongoDB Java Driver v3.2.2 and I use the following instruction to add a new String array field into an existing document:

myMongoCollection.updateOne(new Document("id", id), Updates.set("arrayField", Arrays.asList(new Document("strField", strValue))));

It creates the following exception:

org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.util.Arrays$ArrayList.

Am I doing a coding error or is it related to the Driver bug as suggested here (link)?

If it is related to the driver bug, any hint how I can easily get the latest not-yet-released version (3.3) where is has been fixed (ie. how can I easily create a JAR file, knowing that GIT is completely new to me)?

Many thanks, Tom

1 Answer 1

1

In mongodb-java-driver v3.2.2, you could use Document instead of Updates.set builder. See also Updating Documents

import static com.mongodb.client.model.Filters.eq;

myMongoCollection.updateOne(eq("id", id), new Document("$set", new Document ("arrayField", Arrays.asList(new Document("strField", strValue)))));

Alternatively, if the fix has gone into the master branch, you could build the jar from git:

$ git clone https://github.com/mongodb/mongo-java-driver.git
$ cd mongo-java-driver
$ ./gradlew

The resulting jar would be in build/libs directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.