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命令包含以下字段:
dropSearchIndex | |||
id |
| ||
name |
|
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:dbAdmin和readWrite角色提供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"
} )