Войти через VK Войти через FB Войти через Google Войти через Яндекс
Поиск по сайту
(PECL mongo >=0.9.0)
MongoCollection::ensureIndex — Creates an index on the given field(s), or does nothing if the index already exists
Описаниеpublic bool MongoCollection::ensureIndex ( string|array $key|keys [, array $options = array() ] )
This method creates an index on the collection and the specified fields. The key specification can either be just a single field name as string, or an array containing one or more field names with their sort direction.
An array of fields by which to sort the index on. Each element in the array has as key the field name, and as value either 1 for ascending sort, or -1 for descending sort.
This parameter is an associative array of the form array("optionname" => <boolean>, ...). Currently supported options are:
Create a unique index.Внимание
A unique index cannot be created on a field if multiple existing documents do not contain the field. The field is effectively NULL for these documents and thus already non-unique.
If a unique index is being created and duplicate values exist, drop all but one duplicate value.
If you are using MongoDB version 1.3.2+, you can create indexes in the background while other operations are taking place. By default, index creation happens synchronously. If you specify TRUE with this option, index creation will be asynchronous.
Starting with driver version 1.0.4, you can specify a boolean value for checking if the index creation succeeded. The driver will throw a MongoCursorException if index creation failed.
If you are using replication and the master has changed, using "safe" will make the driver disconnect from the master, throw and exception, and attempt to find a new master on the next operation (your application must decide whether or not to retry the operation on the new master).
If you do not use "safe" with a replica set and the master changes, there will be no way for the driver to know about the change so it will continuously and silently fail to write.
Starting with driver version 1.0.5 you can specify an index name. This can be useful if you are indexing many keys and Mongo complains about the index name being too long.
Integer, defaults to MongoCursor::$timeout. If "safe" is set, this sets how long (in milliseconds) for the client to wait for a database response. If the database does not respond within the timeout period, a MongoCursorTimeoutException will be thrown.
Описание на ru2.php.net
Описание на php.ru