DATAMONGO-1136 - Use $geoWithin instead of $within for geo queries.
We now use the $geoWithin operator for geospatial criteria which requires to run on at least MongoDB 2.4. Original pull request: #263.
This commit is contained in:
committed by
Oliver Gierke
parent
5ed7e8efc2
commit
59e54cecd2
@@ -32,7 +32,7 @@ The jumping off ground for learning about MongoDB is http://www.mongodb.org/[www
|
||||
|
||||
Spring Data MongoDB 1.x binaries requires JDK level 6.0 and above, and http://spring.io/docs[Spring Framework] 3.2.x and above.
|
||||
|
||||
In terms of document stores, http://www.mongodb.org/[MongoDB] preferably version 2.4.
|
||||
In terms of document stores, http://www.mongodb.org/[MongoDB] at least 2.4, preferably version 2.6.
|
||||
|
||||
== Additional Help Resources
|
||||
|
||||
|
||||
@@ -212,11 +212,11 @@ NOTE: Note that for version 1.0 we currently don't support referring to paramete
|
||||
|
||||
| `Within`
|
||||
| `findByLocationWithin(Circle circle)`
|
||||
| `{"location" : {"$within" : {"$center" : [ [x, y], distance]}}}`
|
||||
| `{"location" : {"$geoWithin" : {"$center" : [ [x, y], distance]}}}`
|
||||
|
||||
| `Within`
|
||||
| `findByLocationWithin(Box box)`
|
||||
| `{"location" : {"$within" : {"$box" : [ [x1, y1], x2, y2]}}}True`
|
||||
| `{"location" : {"$geoWithin" : {"$box" : [ [x1, y1], x2, y2]}}}`
|
||||
|
||||
| `IsTrue, True`
|
||||
| `findByActiveIsTrue()`
|
||||
|
||||
@@ -1041,9 +1041,9 @@ As you can see most methods return the `Criteria` object to provide a fluent sty
|
||||
|
||||
There are also methods on the Criteria class for geospatial queries. Here is a listing but look at the section on <<mongo.geospatial,GeoSpatial Queries>> to see them in action.
|
||||
|
||||
* `Criteria` *withinCenter* `(Circle circle)` Creates a geospatial criterion using `$within $center` operators
|
||||
* `Criteria` *withinCenterSphere* `(Circle circle)` Creates a geospatial criterion using `$within $center` operators. This is only available for MongoDB 1.7 and higher.
|
||||
* `Criteria` *withinBox* `(Box box)` Creates a geospatial criterion using a `$within $box` operation ``
|
||||
* `Criteria` *within* `(Circle circle)` Creates a geospatial criterion using `$geoWithin $center` operators.
|
||||
* `Criteria` *within* `(Box box)` Creates a geospatial criterion using a `$geoWithin $box` operation.
|
||||
* `Criteria` *withinSphere* `(Circle circle)` Creates a geospatial criterion using `$geoWithin $center` operators.
|
||||
* `Criteria` *near* `(Point point)` Creates a geospatial criterion using a `$near `operation
|
||||
* `Criteria` *nearSphere* `(Point point)` Creates a geospatial criterion using `$nearSphere$center` operations. This is only available for MongoDB 1.7 and higher.
|
||||
* `Criteria` *maxDistance* `(double maxDistance)` Creates a geospatial criterion using the `$maxDistance` operation, for use with $near.
|
||||
@@ -1073,7 +1073,7 @@ The query methods need to specify the target type T that will be returned and th
|
||||
[[mongo.geospatial]]
|
||||
=== GeoSpatial Queries
|
||||
|
||||
MongoDB supports GeoSpatial queries through the use of operators such as `$near`, `$within`, and `$nearSphere`. Methods specific to geospatial queries are available on the `Criteria` class. There are also a few shape classes, `Box`, `Circle`, and `Point` that are used in conjunction with geospatial related `Criteria` methods.
|
||||
MongoDB supports GeoSpatial queries through the use of operators such as `$near`, `$within`, `geoWithin` and `$nearSphere`. Methods specific to geospatial queries are available on the `Criteria` class. There are also a few shape classes, `Box`, `Circle`, and `Point` that are used in conjunction with geospatial related `Criteria` methods.
|
||||
|
||||
To understand how to perform GeoSpatial queries we will use the following Venue class taken from the integration tests.which relies on using the rich `MappingMongoConverter`.
|
||||
|
||||
@@ -1122,7 +1122,7 @@ To find locations within a `Circle`, the following query can be used.
|
||||
----
|
||||
Circle circle = new Circle(-73.99171, 40.738868, 0.01);
|
||||
List<Venue> venues =
|
||||
template.find(new Query(Criteria.where("location").withinCenter(circle)), Venue.class);
|
||||
template.find(new Query(Criteria.where("location").within(circle)), Venue.class);
|
||||
----
|
||||
|
||||
To find venues within a `Circle` using spherical coordinates the following query can be used
|
||||
@@ -1131,7 +1131,7 @@ To find venues within a `Circle` using spherical coordinates the following query
|
||||
----
|
||||
Circle circle = new Circle(-73.99171, 40.738868, 0.003712240453784);
|
||||
List<Venue> venues =
|
||||
template.find(new Query(Criteria.where("location").withinCenterSphere(circle)), Venue.class);
|
||||
template.find(new Query(Criteria.where("location").withinSphere(circle)), Venue.class);
|
||||
----
|
||||
|
||||
To find venues within a `Box` the following query can be used
|
||||
@@ -1141,7 +1141,7 @@ To find venues within a `Box` the following query can be used
|
||||
//lower-left then upper-right
|
||||
Box box = new Box(new Point(-73.99756, 40.73083), new Point(-73.988135, 40.741404));
|
||||
List<Venue> venues =
|
||||
template.find(new Query(Criteria.where("location").withinBox(box)), Venue.class);
|
||||
template.find(new Query(Criteria.where("location").within(box)), Venue.class);
|
||||
----
|
||||
|
||||
To find venues near a `Point`, the following query can be used
|
||||
|
||||
Reference in New Issue
Block a user