此版本的文档已存档,不再提供支持。要升级6.0部署,请参阅 MongoDB 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 命令接受以下字段:
字段 | 类型 | 必要性 | 说明 |
|---|---|---|---|
| 字符串 | 必需 | 包含要删除的索引的collection名称。 |
| 字符串 | 可选的 |
您必须指定 |
| 字符串 | 可选的 | 要删除的索引的名称。 您必须指定 |
行为
运行dropSearchIndex命令后,在收到命令响应和删除索引之间可能存在延迟。
要查看搜索索引的状态,请使用$listSearchIndexes聚合阶段。 删除索引后,该索引将不再出现在$listSearchIndexes输出中。
访问控制
如果您的部署强制执行访问控制,则运行dropSearchIndex命令的用户必须对数据库或collection具有dropSearchIndex权限操作:
{ resource: { db : <database>, collection: <collection> }, actions: [ "dropSearchIndex" ] }
内置的dbAdmin和readWrite角色提供dropSearchIndex权限。以下示例授予对qa数据库的readWrite角色:
db.grantRolesToUser( "<user>", [ { role: "readWrite", db: "qa" } ] )
输出
成功的dropSearchIndex命令会返回以下内容:
{ ok: 1 }
例子
以下示例删除contacts集合上名为searchIndex01的搜索索引:
db.runCommand( { dropSearchIndex: "contacts", name: "searchIndex01" } )