Results 1 to 2 of 2

Thread: MongoDB GeoNear Query with excluding/including fields criteria

  1. #1
    Join Date
    Mar 2012
    Posts
    7

    Default MongoDB GeoNear Query with excluding/including fields criteria

    Hi, I don't know if I am doing something wrong or it is a bug. I have the following code:

    Query criteria = new Query(Criteria.where("locationTime").gte(
    "date-time"));
    criteria.fields().exclude("friends");

    NearQuery query = NearQuery.near(point).maxDistance(maxDistance)
    .num(limit).query(criteria);
    GeoResults<Profile> result = mongoTemplate
    .geoNear(query, Profile.class);
    I am executing the query and profiles near by retrieved correctly according to distance and the "locationTime" criteria but it seems to ignore the excluded field and retrieving the profiles with their friends.

    When I use simple query the exclude/include fields works perfectly.
    I looked every where and could not find any resemble use-case, please let me know if i am doing something wrong.

    Thanks.

  2. #2

    Default

    I have a similar problem. In my case it does not work the sort:

    Query query = new Query();
    query.with(new Sort(Direction.DESC, "timeStamp"));
    Criteria criteria = new Criteria();
    criteria.and("type").is("MeasurementPoint");
    query.addCriteria(criteria);

    NearQuery queryN = NearQuery.near(p).maxDistance(new Distance(distance, Metrics.KILOMETERS)).num(range).query(query);
    GeoResults<MeasurementPoint> geoPoints = mongoTemplate.geoNear(queryN, MeasurementPoint.class);


    I do not know what I am doing wrong but the geoResult returns me the first match, not the last one (Sorted DESC). So, I assume that the Sort is not working properly.

    Any idea? Is it a bug?

    Thanks!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •