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 –