【发布时间】:2017-12-01 15:53:17
【问题描述】:
@JsonSerialize
@Document(collection = "fence")
@CompoundIndexes({
@CompoundIndex(name = "loc_groupId_idx",
def = "{ 'loc': 2dsphere, 'groups.groupId': 1 }",
unique = false) })
public class GeofenceMongoVO {
public GeofenceMongoVO() {}
@Id
private String fenceId;
@Field
private Long customerId;
@Field
private String fenceName;
@Field
private Byte type;
这就是我尝试确保地理空间字段和子文档(groupId)字段的复合索引的方式。但不幸的是,这不起作用。有没有一种方法可以通过注释确保 java 代码中的 2dsphere 索引?
【问题讨论】:
-
你有一个错字,这就是它不起作用的原因。应该是
"{ 'loc': '2dsphere', 'groups.groupId': 1 }",并在“2dsphere”周围加上引号''。
标签: spring mongodb spring-mongo spring-mongodb