I use spring -data to communicate with mongodb, Iβm looking for a way to execute a geo-request that will be retrieved next to the profiles with a given geodata point from the database, my request requirements:
1) distance limit
2) limit on the number of returned profiles
3) additional time search of the field in the document profile
4) the ability to include / exclude fields from received documents
At first I used the mongoTemplate.geoNear method ...
Query criteria = new Query(Criteria.where("time").gte("some_date")); criteria.fields().exclude("friends"); NearQuery query = NearQuery.near(point).maxDistance(maxDistance) .num(limit).query(criteria); GeoResults<Profile> result = mongoTemplate .geoNear(query, Profile.class);<br/>
But then I realized that mongo does not support the inclusion / exclusion of fields in geoNear queries.
So I think about the Near query, it seems that the only way to execute such a βcomplexβ query in spring-data is using the @Query annotation , is there any way to support the requirements 2,3 above in this kind of query? any other way?
Thanks
source share