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
。
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.runCommand( { planCacheClearFilters: <collection>, query: <query pattern>, sort: <sort specification>, projection: <projection specification>, collation: { <collation> }, comment: <any> } )
命令字段
该命令具有以下字段:
字段 | 类型 | 说明 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
| 字符串 | The name of the collection to remove the index filters from. | ||||||||||
| 文档 | 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
| ||||||||||
| 文档 | Optional. The sort for the index filter to remove, if any. | ||||||||||
| 文档 | Optional. The projection for the index filter to remove, if any. | ||||||||||
| 文档 | 指定用于操作的排序规则。 排序规则允许用户为字符串比较指定特定于语言的规则,例如字母大小写和重音符号规则。 排序规则选项的语法如下:
指定排序规则时, 如果未指定排序规则,但集合具有默认排序规则(请参阅 如果没有为收集或操作指定排序规则,MongoDB 将使用先前版本中使用的简单二进制比较来进行字符串比较。 您不能为一个操作指定多个排序规则。例如,您不能为每个字段指定不同的排序规则,或者如果执行带排序的查找,则不能使用一种排序规则进行查找而另一种排序规则进行排序。 从 MongoDB 6.0 开始,索引筛选器会使用之前使用 从 MongoDB 8.0开始,使用查询设置而不是添加索引筛选器。 从 MongoDB 8.0开始,索引筛选器已弃用。 查询设置的功能比索引筛选器更多。 此外,索引筛选器不是持久性的,您无法轻松地为所有集群节点创建索引筛选器。 要添加查询设置并探索示例,请参阅 | ||||||||||
| any | 可选。用户提供的待附加到该命令的注释。设置后,该注释将与该命令的记录一起出现在以下位置:
注释可以是任何有效的 BSON 类型(字符串、整型、对象、数组等)。 |
必需的访问权限
用户必须具有包括planCacheIndexFilter
操作的访问权限。
示例
Clear Specific Index Filter on Collection
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" } } )
Clear all Index Filters on a Collection
The following example clears all index filters on the orders
collection:
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:
db.runCommand( { planCacheClearFilters: "orders", query: { item: "Movie" }, collation: { locale: "en_US" } } )