Php/docs/mongocollection.getindexinfo

提供:Dev Guides
< Php
移動先:案内検索

MongoCollection::getIndexInfo

(PECL mongo >=0.9.0)

MongoCollection::getIndexInfoこのコレクションのインデックスについての情報を返す


説明

public MongoCollection::getIndexInfo ( ) : array

パラメータ

この関数にはパラメータはありません。


返り値

この関数は、配列を返します。配列の各要素が、それぞれインデックスを表します。 その要素には、インデックス名を表す name や名前空間 (データベース名とコレクション名の組み合わせ) を表す ns、すべてのキーとそのソート順 (インデックスを作るもの) を表す key があります。 また、それ以外の値も特別なインデックスに含まれるかもしれません。 uniquesparse などです。


例1 MongoCollection::getIndexInfo() の例

<?php$m = new MongoClient();$c = $m->selectCollection('test', 'venues');var_dump($c->getIndexInfo());?>

上の例の出力は、 たとえば以下のようになります。


array(4) {
  [0]=>
  array(4) {
    ["v"]=>
    int(1)
    ["key"]=>
    array(1) {
      ["_id"]=>
      int(1)
    }
    ["name"]=>
    string(4) "_id_"
    ["ns"]=>
    string(11) "test.venues"
  }
  [1]=>
  array(4) {
    ["v"]=>
    int(1)
    ["key"]=>
    array(1) {
      ["name"]=>
      float(1)
    }
    ["name"]=>
    string(6) "name_1"
    ["ns"]=>
    string(11) "test.venues"
  }
  [2]=>
  array(4) {
    ["v"]=>
    int(1)
    ["key"]=>
    array(2) {
      ["type"]=>
      float(1)
      ["createdAt"]=>
      float(-1)
    }
    ["name"]=>
    string(19) "type_1_createdAt_-1"
    ["ns"]=>
    string(11) "test.venues"
  }
  [3]=>
  array(5) {
    ["v"]=>
    int(1)
    ["key"]=>
    array(1) {
      ["location"]=>
      string(8) "2dsphere"
    }
    ["name"]=>
    string(17) "location_2dsphere"
    ["ns"]=>
    string(11) "test.venues"
    ["2dsphereIndexVersion"]=>
    int(2)
  }
}

参考

MongoDB コアドキュメントの » vanilla indexes» geospatial indexes も参照ください。