Navigation
This version of the manual is no longer supported.

$polygon

$polygon

New in version 1.9.

Use $polygon to specify a polygon for a bounded query using the $within operator for geospatial queries. To define the polygon, you must specify an array of coordinate points, as in the following:

[ [ x1,y1 ], [x2,y2], [x3,y3] ]

The last point specified is always implicitly connected to the first. You can specify as many points, and therefore sides, as you like. Consider the following bounded query for documents with coordinates within a polygon:

db.collection.find( { loc: { $within: { $polygon: [ [0,0], [3,6], [6,0]  ] } } } )

Changed in version 2.2.3: Before 2.2.3, a geospatial index must exist on a field holding coordinates before using any of the geolocation query operators. After 2.2.3, applications may use geolocation query operators without having a geospatial index; however, geospatial indexes will support much faster geospatial queries than the unindexed equivalents.

Note

A geospatial index must exist on a field and the field must hold coordinates before you can use any of the geolocation query operators.

←   $or $regex  →