diff options
author | Jason Rassi <rassi@10gen.com> | 2015-01-13 17:29:43 -0500 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-01-15 05:41:11 -0500 |
commit | 40f28cd947e8a5227c5a4f6961143ad1b041105f (patch) | |
tree | d0e0fc8663ffe2cfc63916bd677a699660fd6e7d /src/mongo | |
parent | 04237a169a4a8824fd6476617e237c5d69c156c7 (diff) | |
download | mongo-40f28cd947e8a5227c5a4f6961143ad1b041105f.tar.gz |
SERVER-16830 Fix LiteParsedQuery find command object "hint" parsing
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/query/lite_parsed_query.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/query/lite_parsed_query.h | 8 | ||||
-rw-r--r-- | src/mongo/db/query/lite_parsed_query_test.cpp | 3 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/mongo/db/query/lite_parsed_query.cpp b/src/mongo/db/query/lite_parsed_query.cpp index 6e062150abd..d002850122b 100644 --- a/src/mongo/db/query/lite_parsed_query.cpp +++ b/src/mongo/db/query/lite_parsed_query.cpp @@ -116,7 +116,7 @@ namespace mongo { hintObj = cmdObj["hint"].Obj().getOwned(); } else if (String == el.type()) { - hintObj = el.wrap(); + hintObj = el.wrap("$hint"); } else { return Status(ErrorCodes::BadValue, @@ -774,11 +774,13 @@ namespace mongo { if (e.isABSONObj()) { _hint = e.embeddedObject().getOwned(); } - else { - // Hint can be specified as an object or as a string. Wrap takes care of - // it. + else if (String == e.type()) { _hint = e.wrap(); } + else { + return Status(ErrorCodes::BadValue, + "$hint must be either a string or nested object"); + } } else if (str::equals("returnKey", name)) { // Won't throw. diff --git a/src/mongo/db/query/lite_parsed_query.h b/src/mongo/db/query/lite_parsed_query.h index 8e8808d9ad5..d2da40e6684 100644 --- a/src/mongo/db/query/lite_parsed_query.h +++ b/src/mongo/db/query/lite_parsed_query.h @@ -108,7 +108,7 @@ namespace mongo { }; /** - * Parses a count command object, 'cmdObj'. Caller must indicate whether or not + * Parses a find command object, 'cmdObj'. Caller must indicate whether or not * this lite parsed query is an explained query or not via 'isExplain'. * * On success, fills in the out-parameter 'parsedQuery' and returns an OK status. @@ -262,10 +262,14 @@ namespace mongo { BSONObj _filter; BSONObj _sort; BSONObj _proj; - BSONObj _hint; bool _wantMore; bool _explain; + // The hint provided, if any. If the hint was by index key pattern, the value of '_hint' is + // the key pattern hinted. If the hint was by index name, the value of '_hint' is + // {$hint: <String>}, where <String> is the index name hinted. + BSONObj _hint; + Options _options; }; diff --git a/src/mongo/db/query/lite_parsed_query_test.cpp b/src/mongo/db/query/lite_parsed_query_test.cpp index 7ec42f2e0ad..2b5840181f7 100644 --- a/src/mongo/db/query/lite_parsed_query_test.cpp +++ b/src/mongo/db/query/lite_parsed_query_test.cpp @@ -308,7 +308,8 @@ namespace { ASSERT_OK(status); scoped_ptr<LiteParsedQuery> lpq(rawLpq); - ASSERT_EQUALS("foo_1", lpq->getHint().firstElement().str()); + BSONObj hintObj = lpq->getHint(); + ASSERT_EQUALS(BSON("$hint" << "foo_1"), hintObj); } TEST(LiteParsedQueryTest, ParseFromCommandValidSortProj) { |