Docs Menu
Docs Home
/
MongoDB Manual
/ / /

planCacheClearFilters

On this page

  • Definition
  • Compatibility
  • Syntax
  • Required Access
  • Examples
planCacheClearFilters

Removes index filters on a collection. Although index filters only exist for the duration of the server process and do not persist after shutdown, you can also clear existing index filters with the planCacheClearFilters command.

Specify the query shape to remove a specific index filter. Omit the query shape to clear all index filters on a collection.

This command is available in deployments hosted in the following environments:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

Important

This command is not supported in M0, M2, and M5 clusters. For more information, see Unsupported Commands.

The command has the following syntax:

db.runCommand(
{
planCacheClearFilters: <collection>,
query: <query pattern>,
sort: <sort specification>,
projection: <projection specification>,
comment: <any>
}
)

The planCacheClearFilters command has the following field:

Field
Type
Description

planCacheClearFilters

string

The name of the collection.

query

document

Optional. The query predicate associated with the filter to remove. If omitted, clears all filters from the collection.

The values in the query predicate are insignificant in determining the query shape, so the values used in the query need not match the values shown using planCacheListFilters.

sort

document

Optional. The sort associated with the filter to remove, if any.

projection

document

Optional. The projection associated with the filter to remove, if any.

comment

any

Optional. A user-provided comment to attach to this command. Once set, this comment appears alongside records of this command in the following locations:

A comment can be any valid BSON type (string, integer, object, array, etc).

A user must have access that includes the planCacheIndexFilter action.

The orders collection contains the following two filters:

{
"query" : { "status" : "A" },
"sort" : { "ord_date" : -1 },
"projection" : { },
"indexes" : [ { "status" : 1, "cust_id" : 1 } ]
}
{
"query" : { "status" : "A" },
"sort" : { },
"projection" : { },
"indexes" : [ { "status" : 1, "cust_id" : 1 } ]
}

The following command removes the second index filter only:

db.runCommand(
{
planCacheClearFilters: "orders",
query: { "status" : "A" }
}
)

Because the values in the query predicate are insignificant in determining the query shape, the following command would also remove the second index filter:

db.runCommand(
{
planCacheClearFilters: "orders",
query: { "status" : "P" }
}
)

The following example clears all index filters on the orders collection:

db.runCommand(
{
planCacheClearFilters: "orders"
}
)

Tip

See also:

Back

planCacheClear