@@ -4,13 +4,66 @@ db.collection.dropIndex()
4
4
5
5
.. default-domain:: mongodb
6
6
7
- .. method:: db.collection.dropIndex(name )
7
+ .. method:: db.collection.dropIndex(index )
8
8
9
- :param name: The name of the index to drop.
9
+ Drops or removes the specified index from a collection. The
10
+ :method:`db.collection.dropIndex()` method provides a wrapper around
11
+ the :dbcommand:`dropIndexes` command.
12
+
13
+ The :method:`db.collection.dropIndex()` method takes the following
14
+ parameters:
10
15
11
- Drops or removes the specified index. This method provides a
12
- wrapper around the :dbcommand:`dropIndexes`.
16
+ :param index:
17
+
18
+ Either the name or the key of the index to drop. You **must**
19
+ use the name of the index if you specified a name during the
20
+ index creation.
21
+
22
+ The :method:`db.collection.dropIndex()` method cannot drop the
23
+ ``_id`` index. Use the :method:`db.collection.getIndexes()` method
24
+ to view all indexes on a collection.
25
+
26
+ Consider the following examples of the
27
+ :method:`db.collection.dropIndex()` method that assumes the
28
+ following indexes on the collection ``pets``:
29
+
30
+ .. code-block:: javascript
31
+
32
+ > db.pets.getIndexes()
33
+ [
34
+ { "v" : 1,
35
+ "key" : { "_id" : 1 },
36
+ "ns" : "test.pets",
37
+ "name" : "_id_"
38
+ },
39
+ {
40
+ "v" : 1,
41
+ "key" : { "cat" : -1 },
42
+ "ns" : "test.pets",
43
+ "name" : "catIdx"
44
+ },
45
+ {
46
+ "v" : 1,
47
+ "key" : { "cat" : 1, "dog" : -1 },
48
+ "ns" : "test.pets",
49
+ "name" : "cat_1_dog_-1"
50
+ }
51
+ ]
52
+
53
+ - To drop the index on the field ``cat``, you must use the index
54
+ name ``catIdx``:
55
+
56
+ .. code-block:: javascript
57
+
58
+ db.pets.dropIndex( 'catIdx' )
59
+
60
+ - To drop the index on the fields ``cat`` and ``dog``, you can use
61
+ either the index name ``cat_1_dog_-1`` or the key ``{ "cat" : 1,
62
+ "dog" : -1 }``:
63
+
64
+ .. code-block:: javascript
65
+
66
+ db.pets.dropIndex( 'cat_1_dog_-1' )
67
+
68
+ db.pets.dropIndex( { cat : 1, dog : -1 } )
13
69
14
- Use :method:`db.collection.getIndexes()` to get a list of the indexes on the
15
- current collection, and only call :method:`db.collection.dropIndex()` as a
16
- method on a collection object.
0 commit comments