title: Spring mongodb annotation for 2dsphere index for a geospatial field in java...?
body: <pre><code>@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;
  </code></pre>
  
  <p>This is how I tried to ensure a compound index on a geospatial field and a field of a child document(groupId). But this is not working unfortunately. Is there a way by which I can ensure 2dsphere index from java code via annotations?</p>