Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
-
*Location*: http://docs.mongodb.org/manual/reference/operator/query-geospatial/#geospatial-query-compatibility-chart
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36
*Referrer*: http://docs.mongodb.org/manual/applications/geospatial-indexes/
*Screen Resolution*: 2560 x 1440
*repo*: docs
*source*: reference/operator/query-geospatial
*Location*: http://docs.mongodb.org/manual/reference/operator/query-geospatial/#geospatial-query-compatibility-chart *User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.116 Safari/537.36 *Referrer*: http://docs.mongodb.org/manual/applications/geospatial-indexes/ *Screen Resolution*: 2560 x 1440 *repo*: docs *source*: reference/operator/query-geospatial
Description
The example for $geoWithin with $center is not correct:
{ $geoWithin : {
|
$center : [x1, y1],
|
$maxDistance : d
|
} }
|
This is not the right syntax for $center. It doesn't support $maxDistance. That is for the $near operator.
Trying this in the shell returns:
> db.docs.find({loc: {$geoWithin: {$center: [15, 15], $maxDistance:10} }})
|
error: {
|
"$err" : "Malformed geo query: { $geoWithin: { $center: [ 15.0, 15.0 ], $maxDistance: 10.0 } }",
|
"code" : 16677
|
}
|
The correct syntax is explained on the $center page:
{ $geoWithin : {
|
$center :
|
[[x, y], radius]
|
} }
|
It is the same as the $centerSphere syntax.
That also works in the shell:
> db.docs.find({loc: {$geoWithin: {$center: [[15, 15], 10]}}})
|
{ "_id" : ObjectId("51cbb33a7645edc3cf1057cb"), "loc" : [ 10, 20 ] }
|