|
For example, running
db.foo.explain().aggregate([{$redact: "$$KEEP"}, {$match: {a: "A"}}]).stages
|
Gives the following output:
[
|
{
|
"$cursor" : {
|
"queryPlanner" : {
|
"namespace" : "test.foo",
|
"indexFilterSet" : false,
|
"parsedQuery" : {
|
"a" : {
|
"$eq" : "A"
|
}
|
},
|
"queryHash" : "4B53BE76",
|
"planCacheKey" : "4B53BE76",
|
"maxIndexedOrSolutionsReached" : false,
|
"maxIndexedAndSolutionsReached" : false,
|
"maxScansToExplodeReached" : false,
|
"winningPlan" : {
|
"stage" : "COLLSCAN",
|
"filter" : {
|
"a" : {
|
"$eq" : "A"
|
}
|
},
|
"direction" : "forward"
|
},
|
"rejectedPlans" : [ ]
|
}
|
}
|
},
|
{
|
"$match" : {
|
"a" : {
|
"$eq" : "A"
|
}
|
}
|
},
|
{
|
"$redact" : "$$KEEP"
|
},
|
{
|
"$match" : {
|
"a" : {
|
"$eq" : "A"
|
}
|
}
|
}
|
]
|
where the $match after $cursor and before $redact is unexpected.
This is happening because Pipeline::optimizePipeline() is run more than once for each pipeline, and DocumentSourceRedact::doOptimizeAt() adds a $match to the pipeline each time. See here.
|