Skip to content

Commit 0fb84ba

Browse files
Update documentation
1 parent 71192a9 commit 0fb84ba

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepository.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ Window<Person> findByLastnameLikeOrderByLastnameAscFirstnameAsc(String lastname,
221221
List<Person> findByNamedQuery(String firstname);
222222

223223
GeoResults<Person> findByLocationNear(Point point, Distance maxDistance);
224+
224225
GeoResults<Person> findByLocationNearAndLastname(Point point, Distance maxDistance, String Lastname);
225226

226227
// DATAMONGO-1110

src/main/antora/modules/ROOT/pages/mongodb/repositories/query-methods.adoc

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ NOTE: If the property criterion compares a document, the order of the fields and
209209
== Geo-spatial Queries
210210

211211
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.
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
----
223223
public 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
----
234246
interface 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

Comments
 (0)