“文档” 菜单
文档首页
/
MongoDB Manual
/ / /

dropSearchIndex

在此页面上

  • 定义
  • 语法
  • 命令字段
  • 行为
  • 访问控制
  • 输出
  • 例子
dropSearchIndex

7.0 版本中的新增功能:(也可从 6.0.7 开始使用

删除现有的 Atlas Search 索引

mongosh方法 db.collection.dropSearchIndex()提供了updateSearchIndex数据库命令的包装器。

重要

此命令只能在MongoDB Atlas托管的部署上运行,并且需要至少 M 10的 Atlas 集群层。

命令语法:

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

dropSearchIndex 命令接受以下字段:

字段
类型
必要性
说明
dropSearchIndex
字符串
必需
包含要删除的索引的collection名称。
id
字符串
可选的

id 要删除的索引。

您必须指定idname字段。

name
字符串
可选的

要删除的索引的名称。

您必须指定idname字段。

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

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

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

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

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

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

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

{
ok: 1
}

以下示例删除contacts集合上名为searchIndex01的搜索索引:

db.runCommand( {
dropSearchIndex: "contacts",
name: "searchIndex01"
} )
← 创建搜索索引