我在使用聚合框架从 MongoDB 读取文档时遇到问题:我的结果中总是出现空 ID。这仅适用于具有复合 ID 的文档。我尝试了各种版本的 spring-data-mongodb (1.10.12, 2.0.7),结果相同。
实体定义类
@Document(collection="entities")
public class MyEntity {
static class CompositeKey implements Serializable {
private String stringKey;
private Integer intKey;
public CompositeKey(String stringKey, Integer intKey) {
this.stringKey = stringKey;
this.intKey = intKey;
}
public Integer getIntKey() {
return intKey;
}
public String getStringKey() {
return stringKey;
}
public String toString() {
return "{" + stringKey + " - " + intKey + "}";
}
}
@Id
private CompositeKey id;
private String param;
public …Run Code Online (Sandbox Code Playgroud)