首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mongo @DBRef唯一

Mongo @DBRef唯一
EN

Stack Overflow用户
提问于 2015-06-10 22:15:25
回答 1查看 1.4K关注 0票数 1

我的应用程序使用Spring Boot / JPA / MongoDB。

我使用以下命令将域类映射到MongoDB

代码语言:javascript
复制
org.springframework.data.mongodb.core.mapping.Document;
org.springframework.data.mongodb.core.index.Indexed;
org.springframework.data.mongodb.core.mapping.DBRef;

除了尝试让DBRef变得唯一之外,一切都很好:

代码语言:javascript
复制
@DBRef @Indexed(unique = true)
private User owner;

我尝试过@DBRef、@Indexed (unique=true)的不同组合,但无法使DBRef成为唯一的。我可以使其他字段类型唯一,比如下面示例中的‘name

代码语言:javascript
复制
@Indexed(unique = true)
@Size(min = 2, max = 100)
@Column(length = 100)
private String name;

但是找不到如何使我的DBRef字段唯一。

EN

回答 1

Stack Overflow用户

发布于 2015-06-11 21:06:32

我来自映射的Morphia方面,但我会尝试这样做:

代码语言:javascript
复制
@CompoundIndexes({
    @CompoundIndex(name = "owner", def = "{'owner.id' : 1}", unique = true)
})
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30758984

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档