Database Manual / Reference / mongosh Methods / Query Plan Caches

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

Definition定义

db.collection.getPlanCache()

Important

mongosh Method方法

This page documents a mongosh method. This is not the documentation for a language-specific driver, such as Node.js.本页记录了一种mongosh方法。这不是针对特定语言驱动程序(如Node.js)的文档。

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

Returns an interface to access the query plan cache for a collection. The interface provides methods to view and clear the query plan cache.返回一个接口,用于访问集合的查询计划缓存。该界面提供了查看和清除查询计划缓存的方法。

Returns:返回Interface to access the query plan cache.访问查询计划缓存的接口。

The query optimizer only caches the plan for a plan cache query shape that can have more than one viable plan.查询优化器只缓存可以有多个可行计划的计划缓存查询形状的计划。

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的源代码可用、免费使用和自我管理版本

Query Settings查询设置

Starting in MongoDB 8.0, use query settings instead of adding index filters. Index filters are deprecated starting in MongoDB 8.0.从MongoDB 8.0开始,使用查询设置,而不是添加索引筛选器。索引筛选器从MongoDB 8.0开始就被弃用。

Query settings have more functionality than index filters. Also, index filters aren't persistent and you cannot easily create index filters for all cluster nodes. 查询设置比索引筛选器具有更多功能。此外,索引筛选器不是持久的,您无法轻松为所有集群节点创建索引筛选器。To add query settings and explore examples, see setQuerySettings.要添加查询设置并探索示例,请参阅setQuerySettings

Methods方法

The following methods are available through the interface:通过界面可以使用以下方法:

Name名称Description描述
PlanCache.help()Displays the methods available for a collection's query plan cache. Accessible through the plan cache object of a specific collection, i.e. db.collection.getPlanCache().help().显示可用于集合查询计划缓存的方法。可通过特定集合的计划缓存对象访问,即db.collection.getPlanCache().help()
PlanCache.clearPlansByQuery()Clears the cached query plans for the specified plan cache query shape. 清除指定计划缓存查询形状的缓存查询计划。Accessible through the plan cache object of a specific collection, i.e. 可通过特定集合的计划缓存对象访问,即。db.collection.getPlanCache().clearPlansByQuery()
PlanCache.clear()Clears all the cached query plans for a collection. Accessible through the plan cache object of a specific collection, i.e. 清除集合的所有缓存查询计划。可通过特定集合的计划缓存对象访问,即。db.collection.getPlanCache().clear().
PlanCache.list()Returns the plan cache information for a collection. Accessible through the plan cache object of a specific collection, i.e. 返回集合的计划缓存信息。可通过特定集合的计划缓存对象访问,即。db.collection.getPlanCache().list().