简体   繁体   English

Spring Boot项目中MongoDB的一对多和多对一关系

[英]MongoDB One-to-Many and Many-to-One relations in Spring Boot Project

please how can I add relations in a mongoDB cause I just start using it.请问如何在 mongoDB 中添加关系,因为我刚开始使用它。 For example Comment id is a foreign key :例如Comment id 是一个外键

 @Document
    class Comment {

        @Id
        private String id;
        private String text;
        private String author;

        // constructors, getters and setters are ommited
    }

    @Document
    class Article {
        @Id
        private String id;
        @DBRef(lazy = true)
        @CascadeSave
        private List<Comment> comments;
        private String title;
        private String text;

        // constructors, getters and setters are ommited
    }

JPA 注释@OneToMany 和@ManyToMany 的等效项是@DBRef

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM