title: spring data mongo geospatial query
body: <p>I have been trying to use a geospatial query to fetch data into a pojo with no success. </p>
  
  <p>Here is an example data in my monogdb collection</p>
  
  <pre><code>{
      "_id" : ObjectId("597b8c9a21871eeabd5a1cf5"),
      "amb_id" : 10,
      "amb_number" : "KL25 8945",
      "driver_name" : "Amal Shaji",
      "driver_licence_id" : "12/4562/2017",
      "ownership" : "Amrita Institute of Medical Science",
      "ownership_address" : "Peeliyadu Road, Ponekkara, Edappally, Ernakulam",
      "location" : {
          "type" : "Point",
          "coordinates" : [
              76.293485,
              10.032871
          ]
      }
  }
  </code></pre>
  
  <p>The below mongo query works perfectly fine in the mongoshell</p>
  
  <pre><code> db.trial.find( 
    { location : 
    { $near :{ 
      $geometry :{  
        type : "Point" ,  
        coordinates : [ 76.2 , 9.9 ] } ,
        $maxDistance : 20000            }
        } 
  
    } 
    )
    .pretty();
  </code></pre>
  
  <p>Here is the pojo that I have been trying to fetch the data into</p>
  
  <pre><code>@Document(collection = "trial")
      public class Ambulance {
          @Id
          String id;
          @Field("amb_id")
          String ambulanceId;
          @Field("amb_number")
          String licensePlateNumber;
          @Field("driver_name")
          String driverName;
          @Field("driver_licence_id")
          String driverLicenseNumber;
          @Field("ownership")
          String ownerShip;
          @Field("ownership_address")
          String ownerShipAddress;
          @GeoSpatialIndexed(name="Location")
          Double[] location;
  
          //setters and getters
     }
  </code></pre>
  
  <p>Here is the repository I have been using</p>
  
  <pre><code>@ComponentScan
  @Repository
  public interface AmbulanceRepo extends MongoRepository&lt;Ambulance, String&gt; {
    GeoResults&lt;Ambulance&gt; findByLocationNear(Point p, Distance d);
  }
  </code></pre>
  
  <p>and the controller </p>
  
  <pre><code>@RestController
  @CrossOrigin(origins = "http://localhost:4200")
  @RequestMapping("/")
  public class NearbyAmbulanceController {
  
      private AmbulanceRepo ambulanceRepo;
  
      @Autowired
      public NearbyAmbulanceController(AmbulanceRepo repo){
          this.ambulanceRepo = repo;
      }
  
      @RequestMapping(value="/nearbyAmbulance",method = RequestMethod.POST)
      @ResponseBody
      public GeoResults&lt;Ambulance&gt; getAmbulanceDetails(
              @RequestBody LocationRequest locationRequest){
          System.out.println("lati "+locationRequest.getLatitude()+ " long "+locationRequest.getLongitude()+" d "+locationRequest.getDistance());
  //        List&lt;Ambulance&gt; ambulanceList=this.ambulanceRepo.findByLocationNear(new Point(Double.valueOf(locationRequest.getLongitude()),Double.valueOf(locationRequest.getLatitude())),new Distance(locationRequest.getDistance(), Metrics.KILOMETERS));
          Point point = new Point(locationRequest.getLatitude(), locationRequest.getLongitude());
          Distance distance = new Distance(locationRequest.getDistance(), Metrics.KILOMETERS);
          GeoResults&lt;Ambulance&gt; ambulanceList=this.ambulanceRepo.findByLocationNear(point,distance);
          System.out.println(ambulanceList);
          return ambulanceList;
      }
  }
  </code></pre>
  
  <p>Every time I try it I get no results. I am sure that I have data in the given point and nearby locations and I was even able to use the mongoshell to fetch those. I have feeling that the problem is with the way that I have annotated the location field in the entity. Is there anything that I am missing? Any help is appreiciated. </p>