【问题标题】:spring data mongodb NearQuery add another criteriaspring data mongodb NearQuery 添加另一个条件
【发布时间】:2015-06-21 12:00:27
【问题描述】:

是否可以向 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;     
}

我想在查询中添加另一个条件,这可能吗?如何?

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 2019-03-25
    • 1970-01-01
    • 2011-09-24
    • 2017-09-16
    • 1970-01-01
    相关资源
    最近更新 更多