@@ -209,9 +209,9 @@ NOTE: If the property criterion compares a document, the order of the fields and
209209== Geo-spatial Queries
210210
211211As you saw in the preceding table of keywords, a few keywords trigger geo-spatial operations within a MongoDB query.
212- The `Near` keyword allows some further modification, as the next few examples show.
212+ The `Near` and `Within` keywords allows some further modification, as the next few examples show.
213213
214- The following example shows how to define a `near` query that finds all persons with a given distance of a given point :
214+ The following example shows how to define a `near` / `within` query that finds all persons using different shapes :
215215
216216.Advanced `Near` queries
217217[tabs]
@@ -222,8 +222,20 @@ Imperative::
222222----
223223public interface PersonRepository extends MongoRepository<Person, String> {
224224
225- // { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance} }
225+ // { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance } }
226226 List<Person> findByLocationNear(Point location, Distance distance);
227+
228+ // { 'location' : { $geoWithin: { $center: [ [ circle.center.x, circle.center.y ], circle.radius ] } } }
229+ List<Person> findByLocationWithin(Circle circle);
230+
231+ // { 'location' : { $geoWithin: { $box: [ [ box.first.x, box.first.y ], [ box.second.x, box.second.y ] ] } } }
232+ List<Person> findByLocationWithin(Box box);
233+
234+ // { 'location' : { $geoWithin: { $polygon: [ [ polygon.x1, polygon.y1 ], [ polygon.x2, polygon.y2 ], ... ] } } }
235+ List<Person> findByLocationWithin(Polygon polygon);
236+
237+ // { 'location' : { $geoWithin: { $geometry: { $type : 'polygon', coordinates: [[ polygon.x1, polygon.y1 ], [ polygon.x2, polygon.y2 ], ... ] } } } }
238+ List<Person> findByLocationWithin(GeoJsonPolygon polygon);
227239}
228240----
229241
@@ -233,8 +245,20 @@ Reactive::
233245----
234246interface PersonRepository extends ReactiveMongoRepository<Person, String> {
235247
236- // { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance} }
248+ // { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance } }
237249 Flux<Person> findByLocationNear(Point location, Distance distance);
250+
251+ // { 'location' : { $geoWithin: { $center: [ [ circle.center.x, circle.center.y ], circle.radius ] } } }
252+ Flux<Person> findByLocationWithin(Circle circle);
253+
254+ // { 'location' : { $geoWithin: { $box: [ [ box.first.x, box.first.y ], [ box.second.x, box.second.y ] ] } } }
255+ Flux<Person> findByLocationWithin(Box box);
256+
257+ // { 'location' : { $geoWithin: { $polygon: [ [ polygon.x1, polygon.y1 ], [ polygon.x2, polygon.y2 ], ... ] } } }
258+ Flux<Person> findByLocationWithin(Polygon polygon);
259+
260+ // { 'location' : { $geoWithin: { $geometry: { $type : 'polygon', coordinates: [[ polygon.x1, polygon.y1 ], [ polygon.x2, polygon.y2 ], ... ] } } } }
261+ Flux<Person> findByLocationWithin(GeoJsonPolygon polygon);
238262}
239263----
240264======
0 commit comments