Database Manual / Reference / mongosh Methods / MongoDB Search Index

db.collection.dropSearchIndex() (mongosh method方法)

Definition定义

db.collection.dropSearchIndex()

New in version 7.0.在版本7.0中新增。 (Also available starting in 6.0.7从6.0.7开始也可用)

Deletes an existing MongoDB Search index or Vector Search index.删除现有的MongoDB搜索索引矢量搜索索引

Important

mongosh Method

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.本页记录了一种mongosh方法。这不是数据库命令或特定语言驱动程序(如Node.js)的文档。

For the database command, see the dropSearchIndex command.关于数据库命令,请参阅dropSearchIndex命令。

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档

Compatibility兼容性

This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Important

This command is not supported in serverless instances. For more information, see Unsupported Commands.无服务器实例不支持此命令。有关详细信息,请参阅不支持的命令

Syntax语法

Command syntax:命令语法:

db.<collection>.dropSearchIndex(<name>)

Command Fields命令字段

dropSearchIndex() takes the following field:取以下字段:

Field字段Type类型Necessity必要性Description描述
namestring字符串Required必需Name of the search index to drop.要删除的搜索索引的名称。

Behavior行为

After you run dropSearchIndex(), 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() method must have the dropSearchIndex privilege action on the database:如果部署强制执行访问控制,则运行dropSearchIndex()方法的用户必须对数据库具有dropSearchIndex权限操作:

{ resource: { database : true }, actions: [ "dropSearchIndex" ] }

The built-in dbAdmin and readWrite roles provide the dropSearchIndex privilege. 内置的dbAdminreadWrite角色提供dropSearchIndex权限。The following example grants the readWrite role on the qa database:以下示例授予qa数据库上的readWrite角色:

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

Example示例

The following example deletes a search index named searchIndex01 on the movies collection:以下示例删除movies集合上名为searchIndex01的搜索索引:

db.movies.dropSearchIndex("searchIndex01")