planCacheClear
On this page本页内容
Definition定义
planCacheClear
-
Removes cached query plans for a collection. Specify a query shape to remove cached query plans for that shape. Omit the query shape to clear all cached query plans.删除集合的缓存查询计划。指定一个查询形状以删除该形状的缓存查询计划。省略查询形状以清除所有缓存的查询计划。TipIn在mongosh
, this command can also be run through thePlanCache.clear()
andPlanCache.clearPlansByQuery()
helper methods.mongosh
中,该命令也可以通过PlanCache.clear()
和PlanCache.clearPlansByQuery()
辅助方法运行。Helper methods are convenient for助手方法对mongosh
users, but they may not return the same level of information as database commands.mongosh
用户来说很方便,但它们可能不会返回与数据库命令相同级别的信息。In cases where the convenience is not needed or the additional return fields are required, use the database command.如果不需要方便,或者需要额外的返回字段,请使用数据库命令。
Syntax语法
The command has the following syntax:该命令具有以下语法:
db.runCommand(
{
planCacheClear: <collection>,
query: <query>,
sort: <sort>,
projection: <projection>,
comment: <any>
}
)
Command Fields命令字段
The command takes the following optional fields:该命令采用以下可选字段:
query | document | |
projection | document | |
sort | document | |
comment | any | A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:
|
To see the query shapes for which cached query plans exist, see Examples.
Required Access所需访问权限
On systems running with authorization
, a user must have access that includes the planCacheWrite
action.
Examples实例
Clear Cached Plans for a Query Shape
If a collection orders
has the following query shape:
{
"query" : { "qty" : { "$gt" : 10 } },
"sort" : { "ord_date" : 1 },
"projection" : { },
"queryHash" : "9AAD95BE" // Available starting in MongoDB 4.2
}
The following operation clears the query plan cached for the shape:
db.runCommand(
{
planCacheClear: "orders",
query: { "qty" : { "$gt" : 10 } },
sort: { "ord_date" : 1 }
}
)
Clear All Cached Plans for a Collection
The following example clears all the cached query plans for the orders
collection:
db.runCommand(
{
planCacheClear: "orders"
}
)