Spring Boot项目中的MongoDB一对多和多对一关系
请告诉我如何在mongoDB中添加关系,因为我刚刚开始使用它。例如,注释id是外键:Spring Boot项目中的MongoDB一对多和多对一关系,spring,spring-boot,spring-data,embedded-documents,mangodb,Spring,Spring Boot,Spring Data,Embedded Documents,Mangodb,请告诉我如何在mongoDB中添加关系,因为我刚刚开始使用它。例如,注释id是外键: @Document class Comment { @Id private String id; private String text; private String author; // constructors, getters and setters are ommited } @Docume
@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
}
@文档
课堂评论{
@身份证
私有字符串id;
私有字符串文本;
私有字符串作者;
//构造函数、getter和setter是常用的
}
@文件
班级文章{
@身份证
私有字符串id;
@DBRef(lazy=true)
@级联保存
私人名单评论;
私有字符串标题;
私有字符串文本;
//构造函数、getter和setter是常用的
}
JPA注释@OneToMany和@ManyToMany的等效性为@DBRefJPA注释@OneToMany和@ManyToMany的等效性为@DBRef