Spring data mongoDB GeoNear query with excluding fields

点点圈 提交于 2019-12-25 04:17:45

问题


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.


回答1:


There's no way to limit the fields with a geoNear command, as far as I know.

I looked into calling executeCommand to try to work around the limitations of Spring Data, but it looks like they don't even have a way to do it from the raw command.



来源:https://stackoverflow.com/questions/12546389/spring-data-mongodb-geonear-query-with-excluding-fields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!