spring 数据 mongodb NearQuery 添加另一个条件
spring data mongodb NearQuery add another criteria
是否可以向 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;
}
我想在查询中添加另一个条件,是否可行以及如何实现?
只需添加一个额外的查询,如下所示。
NearQuery query = NearQuery.near(new Point(1, 2)).query(Query.query(Criteria.where("foo").is("bar")));
是否可以向 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;
}
我想在查询中添加另一个条件,是否可行以及如何实现?
只需添加一个额外的查询,如下所示。
NearQuery query = NearQuery.near(new Point(1, 2)).query(Query.query(Criteria.where("foo").is("bar")));