1

是否可以将标准添加到NearQuery中?弹簧数据mongodb 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;  
} 

我想另一个标准添加到查询,这可能又如何呢?

回答

3

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

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

让我明白,这是第二个查询入队的操作? – Sanandrea

+0

它与本文所述的'geoNear'的查询条件基本相同http://docs.mongodb.org/manual/reference/command/geoNear/#specify-a-query-condition –