For AI agents: a documentation index is available at https://www.mongodb.com/ja-jp/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs Menu

MongoDB\Model\IndexInfo::is2dSphere()

New in version 1.4. :

MongoDB\Model\IndexInfo::is2dSphere()

Return whether the index is a 2dsphere index.

function is2dSphere(): boolean

A boolean indicating whether the index is a 2dsphere index.

<?php
$collection = (new MongoDB\Client)->getCollection('test', 'places');
$collection->createIndex(['pos' => '2dsphere']);
foreach ($collection->listIndexes() as $index) {
if ($index->is2dSphere()) {
printf("%s has 2dsphereIndexVersion: %d\n", $index->getName(), $index['2dsphereIndexVersion']);
}
}

The output would then resemble:

pos_2dsphere has 2dsphereIndexVersion: 3