MongoDB Spring 引导项目中的一对多和多对一关系
MongoDB One-to-Many and Many-to-One relations in Spring Boot Project
请问如何在 mongoDB 中添加关系,因为我才刚刚开始使用它。例如评论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
请问如何在 mongoDB 中添加关系,因为我才刚刚开始使用它。例如评论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