Docs Menu
Docs Home
/ / /
PHP Library Manual
/ / /

MongoDB\Model\IndexInfo::getKey()

On this page

  • Definition
  • Return Values
  • Examples
  • See Also
MongoDB\Model\IndexInfo::getKey()

Return the index specification (i.e. indexed field(s) and order). This correlates with the $key parameter for MongoDB\Collection::createIndex().

function getKey(): array

The index specification as an associative array.

<?php
$info = new IndexInfo([
'key' => ['x' => 1],
]);
var_dump($info->getKey());

The output would then resemble:

array(1) {
["x"]=>
int(1)
}
  • MongoDB\Collection::createIndex()

  • listIndexes command reference in the MongoDB manual

Back

IndexInfo Class