Database Manual / Reference / Database Commands / Query Plan Cache

planCacheClearFilters (database command)(数据库命令)

Definition定义

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.删除集合上的索引筛选器。虽然索引筛选器仅在服务器进程期间存在,并且在关闭后不会持续存在,但您也可以使用planCacheClearFilters命令清除现有的索引筛选器。

Specify the plan cache query shape to remove a specific index filter. Omit the plan cache query shape to clear all index filters on a collection.指定计划缓存查询形状以删除特定的索引筛选器。省略计划缓存查询形状以清除集合上的所有索引筛选器。

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

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Important

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.M0和Flex集群不支持此命令。有关详细信息,请参阅不支持的命令

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

Syntax语法

The command has the following syntax:该命令具有以下语法:

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

Command Fields命令字段

The command has the following fields:该命令包含以下字段:

Field字段Type类型Description描述
planCacheClearFiltersstring字符串The name of the collection to remove the index filters from.要从中删除索引筛选器的集合的名称。
querydocument文档

Optional. 可选。The query predicate for the index filter to remove. If omitted, the command clears all index filters from the collection.要删除的索引筛选器的查询谓词。如果省略,该命令将从集合中清除所有索引筛选器。

The values in the query predicate do not:query谓词中的值不:

sortdocument文档Optional. 可选。The sort for the index filter to remove, if any.要删除的索引筛选器的排序(如果有的话)。
projectiondocument文档Optional. 可选。The projection for the index filter to remove, if any.索引筛选器要删除的投影(如果有的话)。
collationdocument文档

Specifies the collation to use for the operation.指定用于操作的排序规则

Collation allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks.排序规则允许用户为字符串比较指定特定于语言的规则,例如字母大小写和重音标记的规则。

The collation option has the following syntax:排序规则选项具有以下语法:

collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}

When specifying collation, the locale field is mandatory; all other collation fields are optional. For descriptions of the fields, see Collation Document.指定排序规则时,locale字段是必填的;所有其他排序字段都是可选的。有关字段的描述,请参阅排序规则文档

If the collation is unspecified but the collection has a default collation (see db.createCollection()), the operation uses the collation specified for the collection.如果未指定排序规则,但集合具有默认排序规则(请参阅db.createCollection()),则操作将使用为集合指定的排序规则。

If no collation is specified for the collection or for the operations, MongoDB uses the simple binary comparison used in prior versions for string comparisons.如果没有为集合或操作指定排序规则,MongoDB将使用以前版本中用于字符串比较的简单二进制比较。

You cannot specify multiple collations for an operation. For example, you cannot specify different collations per field, or if performing a find with a sort, you cannot use one collation for the find and another for the sort.不能为操作指定多个排序规则。例如,您不能为每个字段指定不同的排序规则,或者如果使用排序执行查找,则不能对查找使用一个排序规则,对排序使用另一个。

Starting in MongoDB 6.0, an index filter uses the collation previously set using the planCacheSetFilter command.从MongoDB 6.0开始,索引筛选器使用之前使用planCacheSetFilter命令设置的排序规则

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

commentany任意

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).注释可以是任何有效的BSON类型(字符串、整数、对象、数组等)。

Required Access所需访问权限

A user must have access that includes the planCacheIndexFilter action.

Examples示例

Clear Specific Index Filter on Collection清除集合上的特定索引筛选器

The orders collection contains the following index filters:orders集合包含以下索引筛选器:

{
"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 } ]
}

{
"query": { "item": "Movie" },
"collation": { locale: "en_US" },
"indexes": [ { "item": 1, "order_date": 1 , "quantity": 1 } ]
}

Note

Starting in MongoDB 6.0, an index filter uses the collation previously set using the planCacheSetFilter command.从MongoDB 6.0开始,索引筛选器使用之前使用planCacheSetFilter命令设置的排序规则

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

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 plan cache query shape, the following command would also remove the second index filter:由于query谓词中的值在确定计划缓存查询形状时无关紧要,因此以下命令还将删除第二个索引筛选器:

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

Clear all Index Filters on a Collection清除集合上的所有索引筛选器

The following example clears all index filters on the orders collection:以下示例清除orders集合上的所有索引筛选器:

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

Clear Index Filter Containing a Query and a Collation包含查询和排序规则的清除索引筛选器

The following example clears the index filter containing the query on Movie and the collation en_US for the orders collection:以下示例清除了包含对Movie的查询和orders集合的排序规则en_US的索引筛选器:

db.runCommand(
{
planCacheClearFilters: "orders",
query: { item: "Movie" },
collation: { locale: "en_US" }
}
)