我们有一些
users
,一些plots
和一段关系users_have_plots
。详情如下:
@Data
@Document(collection = "users")
public class User {
@Id private String id;
private String email;
private String password;
@DBRef
private List<UserPlot> plots;
}
@Data
@Document(collection = "plots")
@NoArgsConstructor
public class Plot {
@Id
private String id;
private Integer x;
private Integer y;
public Plot(Integer x, Integer y) {
this.x = x;
this.y = y;
}
}
@Data
@Document(collection = "users_have_plots")
public class UserPlot {
@Id
private String id;
@DBRef(lazy = true)
private User user;
@DBRef(lazy = true)
private Plot plot;
private Status status;
private String mnt;
}
目前,我将
UserPlot
设置为有一个 @DbRef 到 User
和 User
有一个 @DbRef 到 UserPlot
。 User
有一个 @DbRef 到 UserPlot
的原因是我想获得用户的所有情节。这种设计是否考虑了 mongo 世界中的最佳/不良实践?
如果不好,请提出解决方案。我需要在用户注册地块时管理两个属性,并有效地获取用户的所有地块。
编辑:它不是基于意见的,因为有很多关于最佳/不良实践的问题,比如宁静命名的最佳实践等