h0m*_*r16 5 mongodb spring-data
我正在开发一个带有 spring 数据和 mongo db 数据库的后端。
我有以下课程
@Document
public class Place
{
@Id
private String id;
@GeoSpatialIndexed
private Double[] location;
private int[] category;
//gets and sets
}
Run Code Online (Sandbox Code Playgroud)
所以我想进行查询以获取具有所选类别的点附近的地方,所以我得到了这个:
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
}
Run Code Online (Sandbox Code Playgroud)
但这没有返回任何结果,我知道查询。
db.place.find( { category: { $all: [ categoryID, categoryID2 ] } } );
Run Code Online (Sandbox Code Playgroud)
效果很好,geoNear 不是问题。
这是一个愚蠢的问题,但 Spring Data for Mongo 的文档和示例非常基础,任何帮助或良好教程或文档的链接都可能会有所帮助,谢谢!:)
我发现问题而不是通过
Query categoryQuery = new Query(new Criteria("category").all(category));
Run Code Online (Sandbox Code Playgroud)
作为类别 int[],我传递 idCategory,idCategory2
Query categoryQuery = new Query(new Criteria("category").all(idCategory,idCategory2));
Run Code Online (Sandbox Code Playgroud)
而且效果很好:)
归档时间: |
|
查看次数: |
7493 次 |
最近记录: |