我的应用程序使用Spring Boot / JPA / MongoDB。
我使用以下命令将域类映射到MongoDB
org.springframework.data.mongodb.core.mapping.Document;
org.springframework.data.mongodb.core.index.Indexed;
org.springframework.data.mongodb.core.mapping.DBRef;除了尝试让DBRef变得唯一之外,一切都很好:
@DBRef @Indexed(unique = true)
private User owner;我尝试过@DBRef、@Indexed (unique=true)的不同组合,但无法使DBRef成为唯一的。我可以使其他字段类型唯一,比如下面示例中的‘name
@Indexed(unique = true)
@Size(min = 2, max = 100)
@Column(length = 100)
private String name;但是找不到如何使我的DBRef字段唯一。
发布于 2015-06-11 21:06:32
我来自映射的Morphia方面,但我会尝试这样做:
@CompoundIndexes({
@CompoundIndex(name = "owner", def = "{'owner.id' : 1}", unique = true)
})https://stackoverflow.com/questions/30758984
复制相似问题