文档菜单
文档首页
/
MongoDB 手册
/ / /

dropSearchIndex

本页内容

  • 定义
  • 语法
  • 命令字段
  • 行为
  • 访问控制
  • 输出
  • 示例
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
条件

id 要删除的索引的 id

您必须指定 任一idname 字段。

name
string
条件

要删除的索引的名称。

您必须指定 任一idname 字段。

运行dropSearchIndex 命令后,您可能会在收到命令响应和索引被删除之间有延迟。

要查看搜索索引的状态,请使用 $listSearchIndexes 聚合阶段。一旦索引被删除,该索引将不再出现在 $listSearchIndexes 输出中。

如果您的部署强制执行访问控制,运行dropSearchIndex 命令后的用户必须具有数据库或集合上的 dropSearchIndex 权限操作

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

内置的 dbAdminreadWrite 角色提供了 dropSearchIndex 权限。以下示例在 qa 数据库上授予 readWrite 角色

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

成功的 dropSearchIndex 命令返回以下内容

{
ok: 1
}

以下示例删除了名为 searchIndex01 的搜索索引,该索引位于 contacts 集合中

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

返回

createSearchIndexes