我正在使用 spring-data-mongodb(版本 1.0.2.RELEASE)和 mongodb(版本 2.2)。我有一个包含对象位置列表的对象 A。课程如下:
public class A {
@Id
private ObjectId id;
private List<Location> places;
//GETTER AND SETTER
}
public class Place {
private String name;
private String description;
@GeoSpatialIndexed
private double[] location;
//GETTER AND SETTER
}
我需要找到具有特定位置的所有对象 A。我尝试将运算符 $within 和 $elemMatch 一起使用,如下所示:
@Query(value = "{'places' : { $elemMatch: { location: {'$within' : {'$center' : [?0, ?1]} } }}}")
public List<A> findByLocation(Point location, double radius);
当我运行此查询时,我收到以下异常:
org.springframework.data.mongodb.UncategorizedMongoDbException: 找不到特殊索引: 2d for: { places: { $elemMatch: { location: { $within: { $center: [ { x: 41.904159, y: 12.549132 }, 0.07000000000000001 ] } } } } }; 嵌套异常是 com.mongodb.MongoException: can't find special index: 2d for: { places: { $elemMatch: { location: { $within: { $center: [ { x: 41.904159, y: 12.549132 }, 0.07000000000000001 ] } } } } }
有什么建议么?
问候