mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
index delete explanation
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@298219 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
08f45dfb40
commit
d1befb8a78
2 changed files with 53 additions and 0 deletions
|
@ -13,6 +13,57 @@
|
|||
<modifier>public</modifier> <type>array</type><methodname>MongoCollection::deleteIndex</methodname>
|
||||
<methodparam><type>string|array</type><parameter>keys</parameter></methodparam>
|
||||
</methodsynopsis>
|
||||
<para>
|
||||
This method is identical to:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
public function deleteIndexes($keys) {
|
||||
// toIndexString is a protected method that turns strings, arrays, and objs
|
||||
//into index names
|
||||
$index = $this->toIndexString($keys);
|
||||
|
||||
return $this->db->command(array("deleteIndexes" => $this->getName(),
|
||||
"index" => $index);
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
Each index, when created, is given a unique name. This is generally user-set
|
||||
(with <function>MongoCollection::ensureIndex</function>'s "name" option) or
|
||||
generated by the driver from a combination of key names and directions. This
|
||||
name is then used by <function>MongoCollection::deleteIndex</function> to
|
||||
remove the function.
|
||||
</para>
|
||||
<para>
|
||||
Unfortunately, the <function>MongoCollection::ensureIndex</function>
|
||||
generates slightly different names than the shell and, due to backwards
|
||||
compatibility issues, <function>MongoCollection::deleteIndex</function>
|
||||
cannot delete custom-named indexes as well. Thus, the best way to delete
|
||||
indexes created in the shell or with custom names is to directly call the
|
||||
<literal>deleteIndexes</literal> database command.
|
||||
</para>
|
||||
<para>
|
||||
Thus, if you named an index "superfast query", you could delete it with:
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$db->command(array("deleteIndexes" => $collection->getName(), "index" => "superfast query");
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
<para>
|
||||
To find what an index is named, you can query the
|
||||
<literal>system.indexes</literal> collection of a database and look for the
|
||||
<literal>name</literal> field.
|
||||
</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1 role="parameters">
|
||||
|
|
|
@ -17,8 +17,10 @@
|
|||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$m = new Mongo(); // connect
|
||||
$db = $m->selectDB("example");
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
|
|
Loading…
Reference in a new issue