Sophie

Sophie

distrib > Mageia > 4 > i586 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 9407

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Deletes an index from this collection</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongocollection.createdbref.html">MongoCollection::createDBRef</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongocollection.deleteindexes.html">MongoCollection::deleteIndexes</a></div>
 <div class="up"><a href="class.mongocollection.html">MongoCollection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongocollection.deleteindex" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoCollection::deleteIndex</h1>
  <p class="verinfo">(PECL mongo &gt;=0.9.0)</p><p class="refpurpose"><span class="refname">MongoCollection::deleteIndex</span> &mdash; <span class="dc-title">Deletes an index from this collection</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongocollection.deleteindex-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">array</span> <span class="methodname"><strong>MongoCollection::deleteIndex</strong></span>
    ( <span class="methodparam"><span class="type"><span class="type string|array">string|array</span></span> <code class="parameter">$keys</code></span>
   )</div>

  <p class="para rdfs-comment">
   This method is identical to:
  </p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">public&nbsp;function&nbsp;</span><span style="color: #0000BB">deleteIndexes</span><span style="color: #007700">(</span><span style="color: #0000BB">$keys</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;toIndexString&nbsp;is&nbsp;a&nbsp;protected&nbsp;method&nbsp;that&nbsp;turns&nbsp;strings,&nbsp;arrays,&nbsp;and&nbsp;objs&nbsp;<br />&nbsp;&nbsp;//into&nbsp;index&nbsp;names<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$index&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">toIndexString</span><span style="color: #007700">(</span><span style="color: #0000BB">$keys</span><span style="color: #007700">);<br /><br />&nbsp;&nbsp;return&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">command</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"deleteIndexes"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(),&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">"index"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$index</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <p class="para">
   Each index, when created, is given a unique name.  This is generally user-set 
   (with  <span class="function"><a href="mongocollection.ensureindex.html" class="function">MongoCollection::ensureIndex()</a></span>&#039;s &quot;name&quot; option) or
   generated by the driver from a combination of key names and directions.  This
   name is then used by  <span class="function"><strong>MongoCollection::deleteIndex()</strong></span> to
   remove the function.
  </p>
  <p class="para">
   Unfortunately, the  <span class="function"><a href="mongocollection.ensureindex.html" class="function">MongoCollection::ensureIndex()</a></span> 
   generates slightly different names than the shell and, due to backwards 
   compatibility issues,  <span class="function"><strong>MongoCollection::deleteIndex()</strong></span>
   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
   <em>deleteIndexes</em> database command.
  </p>
  <p class="para">
   Thus, if you named an index &quot;superfast query&quot;, you could only delete it
   with the PHP driver by running:
  </p>
  <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$db</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">command</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"deleteIndexes"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">(),&nbsp;</span><span style="color: #DD0000">"index"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"superfast&nbsp;query"</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>

  <p class="para">
   To find what an index is named, you can query the 
   <em>system.indexes</em> collection of a database and look for the
   <em>name</em> field.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mongocollection.deleteindex-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term">
      <em><code class="parameter">keys</code></em>
     </span>
     <dd>

      <p class="para">
       Field or fields from which to delete the index.
      </p>
     </dd>

    </dt>
   
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongocollection.deleteindex-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns the database response.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongocollection.deleteindex-examples">
  <h3 class="title">Examples</h3>
  <div class="example" id="example-1438">
   <p><strong>Example #1  <span class="function"><strong>MongoCollection::deleteIndex()</strong></span> example</strong></p>
   <div class="example-contents"><p>
    This example passes the function string and array parameters.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$m&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">MongoClient</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$c&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$m</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">example</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">indices</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;an&nbsp;index<br /></span><span style="color: #0000BB">$c</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ensureIndex</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"i"</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;remove&nbsp;a&nbsp;simple&nbsp;index<br /></span><span style="color: #0000BB">$c</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">deleteIndex</span><span style="color: #007700">(</span><span style="color: #DD0000">"i"</span><span style="color: #007700">);<br /><br /><br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;a&nbsp;multi-key&nbsp;index<br /></span><span style="color: #0000BB">$c</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">ensureIndex</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"j"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"k"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">//&nbsp;remove&nbsp;a&nbsp;multi-key&nbsp;index<br /></span><span style="color: #0000BB">$c</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">deleteIndex</span><span style="color: #007700">(array(</span><span style="color: #DD0000">"j"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"k"&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongocollection.createdbref.html">MongoCollection::createDBRef</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongocollection.deleteindexes.html">MongoCollection::deleteIndexes</a></div>
 <div class="up"><a href="class.mongocollection.html">MongoCollection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>