diff options
author | Benety Goh <benety@mongodb.com> | 2013-12-16 14:08:24 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2013-12-17 14:46:09 -0500 |
commit | b43c12902599e0ecea596975c081655a0cdc121c (patch) | |
tree | 76d1be3ecaccf12b25077b409d6db1119b9a0bd2 /src/mongo/db/query/parsed_projection_test.cpp | |
parent | b1daf8ef3e362a64a9c459c4993d53d0a7b1208d (diff) | |
download | mongo-b43c12902599e0ecea596975c081655a0cdc121c.tar.gz |
SERVER-12117 fixed path checking when parsing projection on $where query
Diffstat (limited to 'src/mongo/db/query/parsed_projection_test.cpp')
-rw-r--r-- | src/mongo/db/query/parsed_projection_test.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/mongo/db/query/parsed_projection_test.cpp b/src/mongo/db/query/parsed_projection_test.cpp index 2f065740db3..debfc387155 100644 --- a/src/mongo/db/query/parsed_projection_test.cpp +++ b/src/mongo/db/query/parsed_projection_test.cpp @@ -134,6 +134,7 @@ namespace { assertInvalidProjection("{a: 1}", "{'a.$.$': 1}"); assertInvalidProjection("{a: 1, b: 1, c: 1}", "{'abc.$': 1}"); assertInvalidProjection("{$or: [{a: 1}, {$or: [{b: 1}, {c: 1}]}]}", "{'d.$': 1}"); + assertInvalidProjection("{a: [1, 2, 3]}", "{'.$': 1}"); } TEST(ParsedProjectionTest, ValidPositionalOperatorProjections) { @@ -151,6 +152,27 @@ namespace { createParsedProjection("{$or: [{a: 1}, {b: 1}]}", "{'b.$': 1}"); createParsedProjection("{$and: [{$or: [{a: 1}, {$and: [{b: 1}, {c: 1}]}]}]}", "{'c.d.f.$': 1}"); + // Fields with empty name can be projected using the positional $ operator. + createParsedProjection("{'': [1, 2, 3]}", "{'.$': 1}"); + } + + // Some match expressions (eg. $where) do not override MatchExpression::path() + // In this test case, we use an internal match expression implementation ALWAYS_FALSE + // to achieve the same effect. + // Projection parser should handle this the same way as an empty path. + TEST(ParsedProjectionTest, InvalidPositionalProjectionDefaultPathMatchExpression) { + auto_ptr<MatchExpression> queryMatchExpr(new FalseMatchExpression()); + ASSERT(NULL == queryMatchExpr->path().rawData()); + + ParsedProjection* out = NULL; + BSONObj projObj = fromjson("{'a.$': 1}"); + Status status = ParsedProjection::make(projObj, queryMatchExpr.get(), &out); + ASSERT(!status.isOK()); + + // Projecting onto empty field should fail. + BSONObj emptyFieldProjObj = fromjson("{'.$': 1}"); + status = ParsedProjection::make(emptyFieldProjObj, queryMatchExpr.get(), &out); + ASSERT(!status.isOK()); } } // unnamed namespace |