@@ -209,9 +209,9 @@ NOTE: If the property criterion compares a document, the order of the fields and
209
209
== Geo-spatial Queries
210
210
211
211
As 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.
213
213
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 :
215
215
216
216
.Advanced `Near` queries
217
217
[tabs]
@@ -222,8 +222,20 @@ Imperative::
222
222
----
223
223
public interface PersonRepository extends MongoRepository<Person, String> {
224
224
225
- // { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance} }
225
+ // { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance } }
226
226
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);
227
239
}
228
240
----
229
241
@@ -233,8 +245,20 @@ Reactive::
233
245
----
234
246
interface PersonRepository extends ReactiveMongoRepository<Person, String> {
235
247
236
- // { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance} }
248
+ // { 'location' : { '$near' : [point.x, point.y], '$maxDistance' : distance } }
237
249
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);
238
262
}
239
263
----
240
264
======
0 commit comments