MongoCollection
PHP Manual

MongoCollection::ensureIndex

(PECL mongo >=0.9.0)

MongoCollection::ensureIndex Creates an index on the given field(s), or does nothing if the index already exists

설명

public boolean MongoCollection::ensureIndex ( string|array $keys )

인수

keys

Field or fields to use as index.

반환값

Returns TRUE.

예제

Example #1 MongoCollection::ensureIndex() example

<?php

$c 
= new MongoCollection($db'foo');

// create an index on 'x' ascending
$c->ensureIndex('x');

// create an index on 'y' ascending
$c->ensureIndex(array('y' => 1));

// create an index on 'w' descending
$c->ensureIndex(array('w' => -1));

// create an index on 'z' ascending and 'zz' descending
$c->ensureIndex(array('z' => 1'zz' => -1));

?>

MongoCollection
PHP Manual