dropSearchIndex
定义
新自版本7.0: (也自6.0.7版本开始可用)
删除现有的Atlas Search 索引.
mongosh
方法db.collection.dropSearchIndex()
提供了围绕 updateSearchIndex
数据库命令的包装。
重要
此命令只能在托管在 MongoDB Atlas 上的部署上运行,并且在 无服务器实例 中 不受支持。
语法
命令语法
db.runCommand( { dropSearchIndex: "<collection name>", id: "<index Id>", name: "<index name>" } )
命令字段
dropSearchIndex
命令接受以下字段
字段 | 类型 | 必要性 | 描述 |
---|---|---|---|
dropSearchIndex | string | 必需 | 包含要删除的索引的集合名称。 |
id | string | 条件 |
您必须指定 任一 的 |
name | string | 条件 | 要删除的索引的名称。 您必须指定 任一 的 |
行为
运行dropSearchIndex
命令后,您可能会在收到命令响应和索引被删除之间有延迟。
要查看搜索索引的状态,请使用 $listSearchIndexes
聚合阶段。一旦索引被删除,该索引将不再出现在 $listSearchIndexes
输出中。
访问控制
如果您的部署强制执行访问控制,运行dropSearchIndex
命令后的用户必须具有数据库或集合上的 dropSearchIndex
权限操作
{ resource: { db : <database>, collection: <collection> }, actions: [ "dropSearchIndex" ] }
内置的 dbAdmin
和 readWrite
角色提供了 dropSearchIndex
权限。以下示例在 qa
数据库上授予 readWrite
角色
db.grantRolesToUser( "<user>", [ { role: "readWrite", db: "qa" } ] )
输出
成功的 dropSearchIndex
命令返回以下内容
{ ok: 1 }
示例
以下示例删除了名为 searchIndex01
的搜索索引,该索引位于 contacts
集合中
db.runCommand( { dropSearchIndex: "contacts", name: "searchIndex01" } )