summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/pipeline')
-rw-r--r--src/mongo/db/pipeline/document_source_match.cpp3
-rw-r--r--src/mongo/db/pipeline/pipeline_test.cpp18
2 files changed, 19 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/document_source_match.cpp b/src/mongo/db/pipeline/document_source_match.cpp
index c2c7ce66f29..ac83ae20f71 100644
--- a/src/mongo/db/pipeline/document_source_match.cpp
+++ b/src/mongo/db/pipeline/document_source_match.cpp
@@ -447,8 +447,7 @@ boost::intrusive_ptr<DocumentSourceMatch> DocumentSourceMatch::descendMatchOnPat
invariant(expression::isPathPrefixOf(descendOn, leafPath));
auto newPath = leafPath.substr(descendOn.size() + 1);
- if (node->getCategory() == MatchExpression::MatchCategory::kLeaf &&
- node->matchType() != MatchExpression::TYPE_OPERATOR) {
+ if (node->getCategory() == MatchExpression::MatchCategory::kLeaf) {
auto leafNode = static_cast<LeafMatchExpression*>(node);
leafNode->setPath(newPath);
} else if (node->getCategory() == MatchExpression::MatchCategory::kArrayMatching) {
diff --git a/src/mongo/db/pipeline/pipeline_test.cpp b/src/mongo/db/pipeline/pipeline_test.cpp
index d6179e48e78..ee5b3153b42 100644
--- a/src/mongo/db/pipeline/pipeline_test.cpp
+++ b/src/mongo/db/pipeline/pipeline_test.cpp
@@ -479,6 +479,24 @@ TEST(PipelineOptimizationTest, LookupShouldAbsorbUnwindMatch) {
assertPipelineOptimizesAndSerializesTo(inputPipe, outputPipe, serializedPipe);
}
+TEST(PipelineOptimizationTest, LookupShouldAbsorbUnwindAndTypeMatch) {
+ string inputPipe =
+ "[{$lookup: {from: 'lookupColl', as: 'asField', localField: 'y', foreignField: "
+ "'z'}}, "
+ "{$unwind: '$asField'}, "
+ "{$match: {'asField.subfield': {$type: [2]}}}]";
+ string outputPipe =
+ "[{$lookup: {from: 'lookupColl', as: 'asField', localField: 'y', foreignField: 'z', "
+ " unwinding: {preserveNullAndEmptyArrays: false}, "
+ " matching: {subfield: {$type: [2]}}}}]";
+ string serializedPipe =
+ "[{$lookup: {from: 'lookupColl', as: 'asField', localField: 'y', foreignField: "
+ "'z'}}, "
+ "{$unwind: {path: '$asField'}}, "
+ "{$match: {'asField.subfield': {$type: [2]}}}]";
+ assertPipelineOptimizesAndSerializesTo(inputPipe, outputPipe, serializedPipe);
+}
+
TEST(PipelineOptimizationTest, LookupWithPipelineSyntaxShouldAbsorbUnwindMatch) {
string inputPipe =
"[{$lookup: {from: 'lookupColl', as: 'asField', pipeline: []}}, "