I am trying to use $geointersects
in mongodb
to find the polygon in which the point is located.
For that in php
i created the test data:
$collection = $db->selectCollection('countries');
$result = $collection->insertMany([
[
'c' => 'rus',
'n' => 'Russia',
'loc' => [
"type" => "Polygon",
"coordinates" => [
[-109.95117, 39.77477],
[-100.23926, 46.70974],
[-94.41608, 37.78902],
[-104.67541, 32.70375],
[-109.95117, 39.77477]
]
]
],[
'c' => 'can',
'n' => 'Canada',
'loc' => [
"type" => "Polygon",
"coordinates" => [
[-100.15137, 46.83013],
[-84.31555, 47.89965],
[-82.39746, 37.78808],
[-94.28467, 37.8228 ],
[-100.15137, 46.83013]
]
]
]
]);
Result is:
Then in Robomongo
I am making a select:
db.getCollection('countries').find({"loc": { $geoIntersects: {$geometry: {"type": "Point", "coordinates": [ -88.0123388, 41.8333926 ]}}}})
And no rows are returned! What might be an issue here?
Same in shell:
Here are the polygons I am testing against:
Here is the point (41.8333926, -88.0123388) location:
Using the latest version of mongodb: 3.2.9.