索引有创建就有删除操作,MongoDB 中,删除索引使用 db.collection.dropIndex() 命令。
命令详解
命令语法
命令的格式如下:
> db.{collection_name}.dropIndex(index)
其中,collection_name 是所要删除索引的集合名称;index 指定针对集合的要删除的索引名称。
命令范例
首先进入指定数据库的上下文:
> use test
switched to db test
假设删除集合 mycol 的 dt 索引:
> db.mycol.dropIndex("idx_dt")
{
"nIndexesWas" : 3,
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1603825148, 1),
"signature" : {
"hash" : BinData(0,"xo9aqsKGHdMqngYVu1jNPN3+Dfw="),
"keyId" : NumberLong("6862526564051976193")
}
},
"operationTime" : Timestamp(1603825148, 1)
}