发布于 2015-09-14 14:56:00 | 98 次阅读 | 评论: 0 | 来源: 网络整理

db.collection.dropIndex(index)

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:

参数:
  • index – Specifies either the name or the key of the index to drop. You must use the name of the index if you specified a name during the index creation.

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 } )
    
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务