diff options
-rw-r--r-- | src/mongo/db/query/planner_ixselect.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/query/query_planner_test.cpp | 9 |
2 files changed, 11 insertions, 1 deletions
diff --git a/src/mongo/db/query/planner_ixselect.cpp b/src/mongo/db/query/planner_ixselect.cpp index 2a64df91ae8..bb23e7c2f3d 100644 --- a/src/mongo/db/query/planner_ixselect.cpp +++ b/src/mongo/db/query/planner_ixselect.cpp @@ -174,10 +174,11 @@ namespace mongo { return false; } - // Can't index negations of MOD, REGEX, or ELEM_MATCH_VALUE. + // Can't index negations of MOD, REGEX, TYPE_OPERATOR, or ELEM_MATCH_VALUE. MatchExpression::MatchType childtype = node->getChild(0)->matchType(); if (MatchExpression::REGEX == childtype || MatchExpression::MOD == childtype || + MatchExpression::TYPE_OPERATOR == childtype || MatchExpression::ELEM_MATCH_VALUE == childtype) { return false; } diff --git a/src/mongo/db/query/query_planner_test.cpp b/src/mongo/db/query/query_planner_test.cpp index 5b8eeef200f..b23da60bc05 100644 --- a/src/mongo/db/query/query_planner_test.cpp +++ b/src/mongo/db/query/query_planner_test.cpp @@ -2893,6 +2893,15 @@ namespace { assertSolutionExists("{cscan: {dir: 1}}"); } + // Negated $type doesn't use the index + TEST_F(QueryPlannerTest, NegationTypeOperator) { + addIndex(BSON("i" << 1)); + runQuery(fromjson("{i: {$not: {$type: 16}}}")); + + assertNumSolutions(1U); + assertSolutionExists("{cscan: {dir: 1}}"); + } + // Negated $elemMatch value won't use the index TEST_F(QueryPlannerTest, NegationElemMatchValue) { addIndex(BSON("i" << 1)); |