【发布时间】:2013-02-02 17:58:48
【问题描述】:
我有一个复合对象,我希望存储在 mongodb 中(使用 spring 注释)。对象如下:
@Document(collection="person")
class Person {
@Id
private String id;
private Address address;
private String name;
}
和复合类地址:
@Document
class Address {
@Indexed
private Long countryId;
private String street;
@Indexed
private String city
}
我需要将国家和城市都编入索引,作为人员集合的一部分。唉,没有为他们创建索引。任何想法如何创建索引?
我尝试了以下方法,但不优雅:
@Document(collection="person")
@CompoundIndexes({
@CompoundIndex(name = "countryId", def = "{'address.countryId': 1}")
})
class Person {
【问题讨论】:
标签: java spring mongodb annotations