小编Gui*_*m S的帖子

具有复合 ID 的 spring-data-mongodb 聚合

我在使用聚合框架从 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)

spring aggregation mongodb

6
推荐指数
1
解决办法
1865
查看次数

标签 统计

aggregation ×1

mongodb ×1

spring ×1