我一直无法找到明确的答案,希望有人可以帮助我。我想在 Mongo 中“引用”的对象上创建一个复合索引。我显然遇到了一个错误,我将在代码片段下方进行描述。
@Entity
public class Address {
public Address (String street, String City, String state, String zip) {
this.street = street;
this.city = city;
this.state = state;
this.zip = zip;
}
// Getters and Setters
@Id private ObjectId id;
private String street;
private String city;
private String state;
private String zip;
}
@Entity
@Indexes( @Index("location.city, name") )
public class Team {
public Team (String sport, String name, Address location) {
this.sport = sport;
this.name = name;
this.location = location;
}
// Getters and Setters
@Id private ObjectId id;
private String sport;
private String name;
@Reference private Address location;
@Reference private List<Player> players;
}
我得到的错误是:
线程“主”com.google.code.morphia.query.ValidationException 中的异常:验证时无法在“com.company.test.Team”中找到“位置”之后的点表示法 - location.city
所以我想我的问题是:我收到这个错误是因为“地址”是“团队”中的引用还是我错过了其他东西?
感谢您的任何反馈。