代码之家  ›  专栏  ›  技术社区  ›  Sabya

java中地理空间字段2dsphere索引的Spring mongodb注释。。。?

  •  3
  • Sabya  · 技术社区  · 7 年前
    @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;
    

    2 回复  |  直到 7 年前
        1
  •  7
  •   user5365075    6 年前

    从Spring Data MongoDB 1.10.10.RELEASE开始,您可以对任何字段进行注释,无论是在文档根还是在子文档中,都可以使用:

    @GeoSpatialIndexed(type = GeoSpatialIndexType.GEO_2DSPHERE)
    private GeoJsonPoint myGeometry;
    
        2
  •  2
  •   p.streef    7 年前

    here

    @Autowired
    MongoTemplate template;
    
    public void setupIndex()
    {
        template.indexOps(Location.class).ensureIndex( new GeospatialIndex("position") );
    }