0
我有一个名为Person.class的类,我有一个称为性的枚举。mongodb编解码器注册表错误,而试图插入Java枚举
public enum Sex{
Male,Female
}
而我有一个变量来把这个枚举值。
private Sex sex = Sex.Male;
public Sex getSex() {
return sex;
}
public void setSex(Sex sex) {
this.sex = sex;
}
其插入,但是当我尝试更新或找回它抛出这个错误被称为
Exception in thread "main" org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class in.co.precisionit.pivot.database.model.Person$Sex.
at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)
at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)
at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:37)
更新查询:
collection.updateOne(eq("employeeList.user", employeeReference),set("user.$.sex", sex)).getModifiedCount();
的检索查询:
Aggregates.unwind("$user");
Aggregates.match(eq("user.sex", sex));
Aggregates.group("$_id", Accumulators.push("user", "$user"));
collection.aggregate(Arrays.asList(unwind, match, group)).first().getUser();
plz some帮帮我。
感谢您的回复。我没有看到一个叫3.6.1的更新版本。 –
http://mongodb.github.io/mongo-java-driver/在他们的首页上列出它。 另外它可以通过maven中心。 – GTFK
它在更新和检索枚举时似乎不起作用。我更新了我的问题 –