MongoDB Java 中的文档更新:编码错误或驱动程序错误?

MongoDB Document Update in Java: coding error or driver bug?

我正在使用 MongoDB Java Driver v3.2.2 并使用以下指令将新的字符串数组字段添加到现有文档中:

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

它创建以下异常:

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

我是在编码错误还是与建议的驱动程序错误有关here (link)

如果它与驱动程序错误有关,任何提示我如何轻松获得最新的尚未发布的版本 (3.3) 已修复(即我如何轻松创建 JAR 文件,知道GIT 对我来说是全新的)?

非常感谢, 汤姆

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)))));

或者,如果修复已进入 master 分支,您可以从 git 构建 jar:

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

生成的 jar 将在 build/libs 目录中。