4
我正在开发一个带弹簧数据和mongo db数据库的后端。用Spring Data查询所有mongo查询
我得到了下面的类
@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的文档和例子都非常基本,任何帮助或者一个好的教程或者文档的链接都可能会有所帮助,谢谢! :)
没你知道你可以添加你自己的答案并接受它(并且可能获得upvotes),而不是用答案编辑问题。在当前状态下,这个问题出现在_unanswered_部分,这是不正确的,因为有解决方案。谢谢:-) – andyb