Rechercher une fonction PHP

MongoCollection::deleteIndex

(PECL mongo >=0.9.0)

MongoCollection::deleteIndexDeletes an index from this collection

Description

public MongoCollection::deleteIndex ( string|array $keys ) : array

This method is identical to:

<?php

public function deleteIndexes($keys) {
  
$indexName $this->toIndexString($keys);

  return 
$this->db->command(array(
    
"deleteIndexes" => $this->getName(),
    
"index" => $indexName,
  ));
}

?>

Each index is given a unique name when it is created. This is often generated by the driver based on the index key(s) and order/type, but custom names may also be specified with MongoCollection::createIndex()'s "name" option).

Unfortunately, MongoCollection::deleteIndex() cannot delete custom-named indexes due to a backwards compatibility issue. When a string argument is provided, it is assumed to be the single field name in an ascending index (e.g. the name "x_1" would be used for the argument "x"). If an array or object is provided, an index name is generated just as if that argument was passed to MongoCollection::createIndex().

In order to delete a custom-named index with the PHP driver, the deleteIndexes database command must be used. For instance, an index named "myIndex" could be deleted with the PHP driver by running:

<?php

$db
->command(array(
  
"deleteIndexes" => $collection->getName(),
  
"index" => "myIndex",
));

?>

To determine the name of an index with the PHP driver, you can query the system.indexes collection of a database and look for the "name" field of each result. The "ns" field will indicate the collection to which each index belongs.

PHP: MongoCollection::deleteIndex - Manual Home of Manuel PHP  Contents Haut

Parameters

keys

An array specifying the index's fields as its keys. For each field, the value is either the index direction or » index type. If specifying direction, specify 1 for ascending or -1 for descending.

If a string is provided, it is assumed to be the single field name in an ascending index.

PHP: MongoCollection::deleteIndex - Manual Home of Manuel PHP  Contents Haut

Return Values

Returns the database response.

PHP: MongoCollection::deleteIndex - Manual Home of Manuel PHP  Contents Haut

Examples

Example #1 MongoCollection::deleteIndex() example

This example passes the function string and array parameters.

<?php

$m 
= new MongoClient();
$c $m->example->indices;

// create and remove a simple index
$c->createIndex(array("i"=>1));
$c->deleteIndex("i");

// create and remove a multi-key index
$c->ensureIndex(array("j" => 1"k" => 1));
$c->deleteIndex(array("j" => 1"k" => 1));

?>

PHP: MongoCollection::deleteIndex - Manual Home of Manuel PHP  Contents Haut

See Also

Find a PHP function

English translation

You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.

If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.

Thank you in advance.

Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-mongocollection.deleteindex.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : http://php.net

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut