1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision: 331062 $ -->
<refentry xml:id="mongocollection.deleteindex" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>MongoCollection::deleteIndex</refname>
<refpurpose>Deletes an index from this collection</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<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 only delete it
with the PHP driver by running:
</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">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term>
<parameter>keys</parameter>
</term>
<listitem>
<para>
Field or fields from which to delete the index.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Returns the database response.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>MongoCollection::deleteIndex</function> example</title>
<para>
This example passes the function string and array parameters.
</para>
<programlisting role="php">
<![CDATA[
<?php
$m = new MongoClient();
$c = $m->example->indices;
// create an index
$c->ensureIndex(array("i"=>1));
// remove a simple index
$c->deleteIndex("i");
// create a multi-key index
$c->ensureIndex(array("j" => 1, "k" => 1));
// remove a multi-key index
$c->deleteIndex(array("j" => 1, "k" => 1));
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
|