For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

MongoDB\Model\CollectionInfo::getIdIndex()

New in version 1.9.

MongoDB\Model\CollectionInfo::getIdIndex()

Returns information about the _id field index.

function getIdIndex(): array

An array containing information on the _id index. This corresponds to the idIndex field returned in the listCollections command reply.

<?php $db = (new MongoDB\Client)->test; $db->createCollection('myCollection'); // Retrieves the _id index informationforeach ($db->listCollections(['filter' => ['name' => 'myCollection']]) as $info) { var_dump($info->getIdIndex());}

The output would then resemble:

array(3) { 'v' => int(2) 'key' => array(1) { '_id' => int(1) } 'name' => string(4) "_id_"}