Docs Menu
Docs Home
/
MongoDB Manual
/ / /

db.collection.getPlanCache()

On this page

  • Definition
  • Methods
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.

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.

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.

Starting in MongoDB 8.0, use query settings instead of adding index filters. Index filters are deprecated starting in 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.

The following methods are available through the interface:

Name
Description
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().
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()
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().
Returns the plan cache information for a collection. Accessible through the plan cache object of a specific collection, i.e. db.collection.getPlanCache().list().

Back

Query Plan Caches

On this page