尝试插入java枚举时mongodb编解码器注册表错误
我有一个名为Person.class的类,其中有一个名为sex的枚举尝试插入java枚举时mongodb编解码器注册表错误,java,mongodb,enums,Java,Mongodb,Enums,我有一个名为Person.class的类,其中有一个名为sex的枚举 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
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();
请帮忙。我今天也遇到了这个问题。
这似乎是3.6.0驱动程序中的一个bug。有一个新版本(3.6.1)似乎没有这个问题。感谢您的回复。我没有看到一个叫做3.6.1的更新版本会出现在他们的头版。它也可以通过maven central获得。在更新和检索枚举时,它似乎不起作用。我已经更新了我的问题