问题
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