Docs 菜单

planCacheClearFilters

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 计划缓存查询结构 to remove a specific index filter. Omit the plan cache query shape to clear all index filters on a collection.

从 MongoDB 8.0开始,使用查询设置而不是添加索引筛选器。 从 MongoDB 8.0开始,索引筛选器已弃用。

查询设置的功能比索引筛选器更多。 此外,索引筛选器不是持久性的,您无法轻松地为所有集群节点创建索引筛选器。 要添加查询设置并探索示例,请参阅setQuerySettings

此命令可用于以下环境中托管的部署:

重要

M0 、M2 、M5 和 Flex 集群不支持此命令。有关更多信息,请参阅不支持的命令。

该命令具有以下语法:

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

该命令具有以下字段:

字段
类型
说明

planCacheClearFilters

字符串

The name of the collection to remove the index filters from.

query

文档

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:

sort

文档

Optional. The sort for the index filter to remove, if any.

projection

文档

Optional. The projection for the index filter to remove, if any.

collation

文档

指定用于操作的排序规则

排序规则允许用户为字符串比较指定特定于语言的规则,例如字母大小写和重音符号规则。

排序规则选项的语法如下:

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

指定排序规则时,locale 字段为必填字段;所有其他排序规则字段均为可选字段。有关字段的说明,请参阅排序规则文档

如果未指定排序规则,但集合具有默认排序规则(请参阅 db.createCollection()),则操作将使用为集合指定的排序规则。

如果没有为收集或操作指定排序规则,MongoDB 将使用先前版本中使用的简单二进制比较来进行字符串比较。

您不能为一个操作指定多个排序规则。例如,您不能为每个字段指定不同的排序规则,或者如果执行带排序的查找,则不能使用一种排序规则进行查找而另一种排序规则进行排序。

从 MongoDB 6.0 开始,索引筛选器会使用之前使用 planCacheSetFilter 命令设置的排序规则

从 MongoDB 8.0开始,使用查询设置而不是添加索引筛选器。 从 MongoDB 8.0开始,索引筛选器已弃用。

查询设置的功能比索引筛选器更多。 此外,索引筛选器不是持久性的,您无法轻松地为所有集群节点创建索引筛选器。 要添加查询设置并探索示例,请参阅setQuerySettings

comment

any

可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:

注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。

用户必须具有包括planCacheIndexFilter操作的访问权限。

The orders collection contains the following index 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 } ]
}
{
"query": { "item": "Movie" },
"collation": { locale: "en_US" },
"indexes": [ { "item": 1, "order_date": 1 , "quantity": 1 } ]
}

注意

从 MongoDB 6.0 开始,索引筛选器会使用之前使用 planCacheSetFilter 命令设置的排序规则

从 MongoDB 8.0开始,使用查询设置而不是添加索引筛选器。 从 MongoDB 8.0开始,索引筛选器已弃用。

查询设置的功能比索引筛选器更多。 此外,索引筛选器不是持久性的,您无法轻松地为所有集群节点创建索引筛选器。 要添加查询设置并探索示例,请参阅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:

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

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

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

The following example clears the index filter containing the query on Movie and the collation en_US for the orders collection:

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