On this page
dropIndexes
dropIndexes
- dropIndexes命令从指定集合中删除一个或所有非
_id
索引。
- dropIndexes命令从指定集合中删除一个或所有非
该命令具有以下形式:
{ dropIndexes: <string>, index: <string|document>, writeConcern: <document>}
该命令包含以下字段:
Field | Description |
---|---|
dropIndexes | 要删除其索引的集合的名称。 |
index | 要删除的索引的名称或规格文件。 |
要从集合中删除所有非_id
索引,请指定"*"
。
要删除text索引,请指定索引名称。
| writeConcern |可选。表示drop命令的write concern的文档。忽略使用默认的写关注。
要删除所有非_id
的索引,请为index
指定"*"
(请参见 ref:3.6-index-asterisk)。
{ dropIndexes: "collection", index: "*" }
要删除单个索引,请通过指定要删除的索引的名称来发出命令。例如,要删除名为age_1
的索引,请使用以下命令:
{ dropIndexes: "collection", index: "age_1" }
Shell 程序提供了有用的命令帮助器。这是等效的命令:
db.collection.dropIndex("age_1");
Warning
此命令在受影响的数据库上获得写锁定,并将阻止其他操作,直到完成为止。