Java spring mongodb中的索引复合对象
我希望在mongodb中存储一个复合对象(使用spring注释)。目标如下:Java spring mongodb中的索引复合对象,java,spring,mongodb,annotations,Java,Spring,Mongodb,Annotations,我希望在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 stree
@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 {
如果愿意,您可以设置多个。这将是一个很好的起点。谢谢。但这并没有真正的帮助。首先,所有索引在mongodb中都是次要的。其次,我正在寻找java/spring解决方案。