Docs HomeMongoDB Manual

PlanCache.clear()

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.

For the database command, see the planCacheClear command.

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

For the legacy mongo shell documentation, refer to the documentation for the corresponding MongoDB Server release:对于遗留的mongoshell文档,请参阅相应MongoDB Server版本的文档:

mongo shell v4.4

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()

Required Access所需访问权限

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