【问题标题】:Indexing composite object in spring mongodb在spring mongodb中索引复合对象
【发布时间】: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


    【解决方案1】:

    如果您愿意,您可以设置多个secondary indexes。这将是一个很好的起点。

    【讨论】:

    • 谢谢。但这并没有真正的帮助。首先,所有索引在 mongodb 中都是次要的。其次,我正在寻找一个java/spring的解决方案。
    猜你喜欢
    • 2016-12-15
    • 1970-01-01
    • 2015-03-04
    • 2012-03-24
    • 2016-07-10
    • 2018-01-22
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多