0

我有一个复合对象,我希望存储在 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 {
4

1 回答 1

1

You can set up multiple secondary indexes, if you wish. This would be a good place to start.

于 2013-02-20T17:03:03.190 回答