翻译或纠错本页面
- Reference >
- Operators >
- Query and Projection Operators >
- Geospatial Query Operators
Geospatial Query Operators¶
Operators¶
Query Selectors¶
Name | Description |
---|---|
$geoWithin | Selects geometries within a bounding GeoJSON geometry. |
$geoIntersects | Selects geometries that intersect with a GeoJSON geometry. |
$near | Returns geospatial objects in proximity to a point. |
$nearSphere | Returns geospatial objects in proximity to a point on a sphere. |
Geometry Specifiers¶
Name | Description |
---|---|
$geometry | Specifies a geometry in GeoJSON format to geospatial query operators. |
$minDistance | Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. |
$maxDistance | Specifies a maximum distance to limit the results of $near and $nearSphere queries. |
$center | Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. |
$centerSphere | Specifies a circle using either legacy coordinate pairs or GeoJSON format for $geoWithin queries when using spherical geometry. |
$box | Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. |
$polygon | Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. |
$uniqueDocs | Deprecated. Modifies a $geoWithin and $near queries to ensure that even if a document matches the query multiple times, the query returns the document once. |
Geospatial Query Compatibility¶
While numerous combinations of query operators are possible, the following table shows the recommended operators for different types of queries. The table uses the $geoWithin, $geoIntersects and $near operators.
Query Document | Geometry of the Query Condition | Surface Type for Query Calculation | Units for Query Calculation | Supported by this Index |
---|---|---|---|---|
Returns points, lines and polygons | ||||
{ $geoWithin : {
$geometry : <GeoJSON Polygon>
} }
|
polygon | sphere | meters | 2dsphere |
{ $geoIntersects : {
$geometry : <GeoJSON>
} }
|
point, line or polygon | sphere | meters | 2dsphere |
{ $near : {
$geometry : <GeoJSON Point>,
$maxDistance : d
} }
|
point | sphere | meters | 2dsphere The index is required. |
Returns points only | ||||
{ $geoWithin : {
$box : [[x1, y1], [x2, y2]]
} }
|
rectangle | flat | flat units | 2d |
{ $geoWithin : {
$polygon : [[x1, y1],
[x1, y2],
[x2, y2],
[x2, y1]]
} }
|
polygon | flat | flat units | 2d |
{ $geoWithin : {
$center : [[x1, y1], r],
} }
|
circular region | flat | flat units | 2d |
{ $geoWithin : {
$centerSphere :
[[x, y], radius]
} }
|
circular region | sphere | radians | 2d 2dsphere |
{ $near : [x1, y1],
$maxDistance : d
}
|
point | flat / flat units | flat units | 2d The index is required. |