Database Manual / Reference / mongosh Methods / Query Plan Caches

PlanCache.clear() (mongosh method方法)

Definition定义

PlanCache.clear()

Removes all cached query plans for a collection.删除集合的所有缓存查询计划。

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 planCacheClear command.关于数据库命令,请参阅planCacheClear命令。

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

The method is only available from the plan cache object of a specific collection; i.e.该方法仅在特定集合的计划缓存对象中可用;即。

db.collection.getPlanCache().clear()

For example, to clear the cache for the orders collection:例如,要清除orders集合的缓存:

db.orders.getPlanCache().clear()

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部署的完全托管服务
  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本

Required Access所需访问权限

On systems running with authorization, a user must have access that includes the planCacheWrite action.authorization运行的系统上,用户必须具有包含planCacheWrite操作的访问权限。