Definition定义
planCacheClearFiltersRemoves 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删除集合上的索引筛选器。虽然索引筛选器仅在服务器进程期间存在,并且在关闭后不会持续存在,但您也可以使用planCacheClearFilterscommand.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:该命令包含以下字段:
planCacheClearFilters | ||
query |
| |
sort | ||
projection | ||
collation |
| |
comment |
|
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 从MongoDB 6.0开始,索引筛选器使用之前使用planCacheSetFilter command.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" }
}
)