I'm trying to run some simple integration tests which store some Checkin domain objects in a Mongo collection, and then run a simple geospatial query to return some based on a particular location, however, mongod throws the below error once the query is run:
Code:can't find special index: 2d for: { location: { $within: { $center: [ [ 34.0269 , -118.4737 ], 0.01 ] } } }; nested exception is com.mongodb.MongoException: can't find special index: 2d for: { location: { $within: { $center: [ [ 34.0269, -118.4737 ], 0.01 ] } } }
Domain object code:
Code:@Document(collection = "checkin") public class Checkin implements ICheckin { @Id private String id; @GeoSpatialIndexed private double[] location; public double[] getLocation() { return location; } public void setLocation(double[] location) { this.location = location; } ..
Custom query for checkins by location:
I can tell my index is not being created for some reason, but what am I doing wrong?Code:@Autowired private MongoTemplate mongoTemplate; public List<Checkin> findByLocation(double lat, double lon, double radius) { mongoTemplate.ensureIndex(new GeospatialIndex("location")); Circle circle = new Circle(lat, lon, radius); List<Checkin> checkins = mongoTemplate.find(new Query(Criteria.where("location").withinCenter(circle)), Checkin.class); return checkins; }


Reply With Quote
