@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;
从Spring Data MongoDB 1.10.10.RELEASE开始,您可以对任何字段进行注释,无论是在文档根还是在子文档中,都可以使用:
@GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE) private GeoJsonPoint myGeometry;
here
@Autowired MongoTemplate template; public void setupIndex() { template.indexOps(Location.class).ensureIndex( new GeospatialIndex("position") ); }