【发布时间】:2012-05-30 02:51:37
【问题描述】:
我正在开发一个带有 spring 数据和一个 mongo db 数据库的后端。
我有以下课程
@Document
public class Place
{
@Id
private String id;
@GeoSpatialIndexed
private Double[] location;
private int[] category;
//gets and sets
}
所以我想进行查询以获取具有所选类别的点附近的地方,所以我得到了这个:
public List<Place> getPlacesNear(Double[] location, int[] category){
NearQuery geoNear = NearQuery.near(location[0],location[1],Metrics.KILOMETERS).maxDistance(KM_DISTANCE);
Query categoryQuery = new Query(new Criteria("category").all(category));
geoNear.query(categoryQuery);
GeoResults<Place> geoNearResult = mongoTemplate.geoNear(geoNear, Place.class);
//return results
}
但这并没有返回任何结果,我知道查询。
db.place.find( { category: { $all: [ categoryID, categoryID2 ] } } );
效果很好,geoNear 不是问题。
这是一个愚蠢的问题,但是 Mongo 的 Spring Data 的文档和示例非常基础,任何帮助或一个好的教程或文档的链接都可能会有所帮助,谢谢! :)
【问题讨论】:
-
您知道吗?您可以添加自己的答案并接受它(并且可能会获得赞成票),而不是用答案编辑问题。在当前状态下,这个问题出现在 unanswered 部分,这是不正确的,因为有解决方案。谢谢:-)
标签: mongodb spring-data