Database Manual / Reference / Database Commands / MongoDB Search

dropSearchIndex (database command数据库命令)

Definition定义

dropSearchIndex

New in version 7.0.在版本7.0中新增。 (Also available starting in 6.0.7从6.0.7开始也可用)

Deletes an existing MongoDB Search index.删除现有的MongoDB搜索索引

The mongosh method db.collection.dropSearchIndex() provides a wrapper around the updateSearchIndex database command.mongosh方法db.collection.dropSearchIndex()updateSearchIndex数据库命令提供了一个包装器。

Important

This command can only be run on a deployment hosted on MongoDB Atlas.此命令只能在MongoDB Atlas上托管的部署上运行。

Syntax语法

Command syntax:命令语法:

db.runCommand(
{
dropSearchIndex: "<collection name>",
id: "<index Id>",
name: "<index name>"
}
)

Command Fields命令字段

The dropSearchIndex command takes the following fields:dropSearchIndex命令包含以下字段:

Field字段Type类型Necessity必要性Description描述
dropSearchIndexstring字符串Required必需Name of the collection that contains the index to delete.包含要删除的索引的集合的名称。
idstring字符串Conditional附条件

id of the index to delete.要删除的索引的id

You must specify either the id or name field.您必须指定idname字段。

namestring字符串Conditional附条件

You must specify either the id or name field.您必须指定idname字段。

Behavior行为

After you run the dropSearchIndex command, there may be a delay between when you receive a response from the command and when the index is deleted.运行dropSearchIndex命令后,从收到命令的响应到删除索引之间可能会有延迟。

To see the status of your search indexes, use the $listSearchIndexes aggregation stage. Once your index is deleted, that index no longer appears in the $listSearchIndexes output.要查看搜索索引的状态,请使用$listSearchIndexes聚合阶段。删除索引后,该索引将不再出现在$listSearchIndexes输出中。

Access Control访问控制

If your deployment enforces access control, the user running the dropSearchIndex command must have the dropSearchIndex privilege action on the database or collection:如果部署强制执行访问控制,则运行dropSearchIndex命令的用户必须对数据库或集合具有dropSearchIndex权限操作:

{
resource: {
db : <database>,
collection: <collection>
},
actions: [ "dropSearchIndex" ]
}

The built-in dbAdmin and readWrite roles provide the dropSearchIndex privilege. The following example grants the readWrite role on the qa database:内置的dbAdminreadWrite角色提供dropSearchIndex权限。以下示例授予qa数据库上的readWrite角色:

db.grantRolesToUser(
"<user>",
[ { role: "readWrite", db: "qa" } ]
)

Output输出

A successful dropSearchIndex command returns the following:成功的dropSearchIndex命令返回以下内容:

{
ok: 1
}

Example示例

The following example deletes a search index named searchIndex01 on the contacts collection:以下示例删除contacts集合上名为searchIndex01的搜索索引:

db.runCommand( {
dropSearchIndex: "contacts",
name: "searchIndex01"
} )