发布于 2015-09-14 14:56:00 | 105 次阅读 | 评论: 0 | 来源: 网络整理
Drops or removes the specified index from a collection. The db.collection.dropIndex() method provides a wrapper around the dropIndexes command.
The db.collection.dropIndex() method takes the following parameter:
参数: |
|
---|
The db.collection.dropIndex() method cannot drop the _id index. Use the db.collection.getIndexes() method to view all indexes on a collection.
Consider the following examples of the db.collection.dropIndex() method that assumes the following indexes on the collection pets:
> db.pets.getIndexes()
[
{ "v" : 1,
"key" : { "_id" : 1 },
"ns" : "test.pets",
"name" : "_id_"
},
{
"v" : 1,
"key" : { "cat" : -1 },
"ns" : "test.pets",
"name" : "catIdx"
},
{
"v" : 1,
"key" : { "cat" : 1, "dog" : -1 },
"ns" : "test.pets",
"name" : "cat_1_dog_-1"
}
]
To drop the index on the field cat, you must use the index name catIdx:
db.pets.dropIndex( 'catIdx' )
To drop the index on the fields cat and dog, you use either the index name cat_1_dog_-1 or the key { "cat" : 1, "dog" : -1 }:
db.pets.dropIndex( 'cat_1_dog_-1' )
db.pets.dropIndex( { cat : 1, dog : -1 } )