spring data mongodb NearQuery添加了另一个标准

时间:2015-04-15 13:34:02

标签: spring mongodb spring-data spring-data-mongodb spring-mongo

是否可以将标准添加到NearQuery?

目前我这样做:

public List<UserLocation> getUserNearLocation(Point p, double min, double max){
    NearQuery query = NearQuery.near(p).minDistance(new Distance(min, Metrics.KILOMETERS)).maxDistance(new Distance(max, Metrics.KILOMETERS));
    GeoResults<UserLocation> results = mongoTemplate.geoNear(query, UserLocation.class);

    List<UserLocation> all = new ArrayList<UserLocation>();
    Iterator<GeoResult<UserLocation>> iter = results.iterator();
    while (iter.hasNext()){
        GeoResult<UserLocation> temp = iter.next();
        all.add(temp.getContent());
    }

    return all;     
}

我想为查询添加另一个标准,是否可能以及如何?

1 个答案:

答案 0 :(得分:3)

只需添加如下所示的其他查询。

NearQuery query = NearQuery.near(new Point(1, 2)).query(Query.query(Criteria.where("foo").is("bar")));