summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2015-01-13 17:29:43 -0500
committerJason Rassi <rassi@10gen.com>2015-01-15 05:41:11 -0500
commit40f28cd947e8a5227c5a4f6961143ad1b041105f (patch)
treed0e0fc8663ffe2cfc63916bd677a699660fd6e7d
parent04237a169a4a8824fd6476617e237c5d69c156c7 (diff)
downloadmongo-40f28cd947e8a5227c5a4f6961143ad1b041105f.tar.gz
SERVER-16830 Fix LiteParsedQuery find command object "hint" parsing
-rw-r--r--jstests/core/explain_shell_helpers.js6
-rw-r--r--src/mongo/db/query/lite_parsed_query.cpp10
-rw-r--r--src/mongo/db/query/lite_parsed_query.h8
-rw-r--r--src/mongo/db/query/lite_parsed_query_test.cpp3
4 files changed, 20 insertions, 7 deletions
diff --git a/jstests/core/explain_shell_helpers.js b/jstests/core/explain_shell_helpers.js
index 6ed86f8c6b0..8b49588ff8e 100644
--- a/jstests/core/explain_shell_helpers.js
+++ b/jstests/core/explain_shell_helpers.js
@@ -122,9 +122,15 @@ assert(planHasStage(explain.queryPlanner.winningPlan, "SORT"));
explain = t.explain().find().hint({a: 1}).finish();
assert.commandWorked(explain);
assert(isIxscan(explain.queryPlanner.winningPlan));
+explain = t.explain().find().hint("a_1").finish();
+assert.commandWorked(explain);
+assert(isIxscan(explain.queryPlanner.winningPlan));
explain = t.find().hint({a: 1}).explain();
assert.commandWorked(explain);
assert(isIxscan(explain.queryPlanner.winningPlan));
+explain = t.find().hint("a_1").explain();
+assert.commandWorked(explain);
+assert(isIxscan(explain.queryPlanner.winningPlan));
// .min()
explain = t.explain().find().min({a: 1}).finish();
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) {