Create geo index 2dsphere
public ensure2dIndex ( string $field ) : |
||
$field | string | |
return |
public function testExpressionWithinPolygon() { $this->collection->ensure2dIndex('point'); $point1Id = $this->collection->createDocument()->setLegacyPoint('point', 5, 4)->save()->getId(); $point2Id = $this->collection->createDocument()->setLegacyPoint('point', 50, 40)->save()->getId(); $point = $this->collection->find()->withinPolygon('point', array(array(0, 0), array(0, 10), array(10, 10), array(10, 0)))->findOne(); $this->assertNotEmpty($point); $this->assertEquals($point1Id, $point->getId()); }