Announcement Announcement Module
Collapse
No announcement yet.
MongoDB GeoNear Query with excluding/including fields criteria Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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!

    Comment


    • #3
      "mongoTemplate.geoNear()" executes "geoNear" command. MongoDB doesn't support fields projection or sorting for this command.
      http://docs.mongodb.org/manual/refer...mmand/geoNear/

      It is possible to query using $near and calculate distance by yourself.

      Comment

      Working...
      X