summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/canonical_query_test.cpp
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2016-02-02 13:17:50 -0500
committerTess Avitabile <tess.avitabile@mongodb.com>2016-02-03 10:25:51 -0500
commitbb2f3aebc4c4ce5fd15c44ebca6d66dc0542562d (patch)
treed919d4bc67bac7f771daa5bb47d260d8c15e33a7 /src/mongo/db/query/canonical_query_test.cpp
parent407457dc34ea5afc3b983096c80959815b888632 (diff)
downloadmongo-bb2f3aebc4c4ce5fd15c44ebca6d66dc0542562d.tar.gz
SERVER-8564 An index hint inconsistent with requested natural order sort should be an error
Diffstat (limited to 'src/mongo/db/query/canonical_query_test.cpp')
-rw-r--r--src/mongo/db/query/canonical_query_test.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp
index 0e9a0a60d04..d56c1814ebd 100644
--- a/src/mongo/db/query/canonical_query_test.cpp
+++ b/src/mongo/db/query/canonical_query_test.cpp
@@ -425,6 +425,33 @@ TEST(CanonicalQueryTest, IsValidSortKeyMetaProjection) {
}
}
+TEST(CanonicalQueryTest, IsValidNaturalSortIndexHint) {
+ const bool isExplain = false;
+ auto lpq = assertGet(LiteParsedQuery::makeFromFindCommand(
+ nss, fromjson("{find: 'testcoll', sort: {$natural: 1}, hint: {a: 1}}"), isExplain));
+
+ // Invalid: {$natural: 1} sort order and index hint.
+ ASSERT_NOT_OK(isValid("{}", *lpq));
+}
+
+TEST(CanonicalQueryTest, IsValidNaturalSortNaturalHint) {
+ const bool isExplain = false;
+ auto lpq = assertGet(LiteParsedQuery::makeFromFindCommand(
+ nss, fromjson("{find: 'testcoll', sort: {$natural: 1}, hint: {$natural: 1}}"), isExplain));
+
+ // Valid: {$natural: 1} sort order and {$natural: 1} hint.
+ ASSERT_OK(isValid("{}", *lpq));
+}
+
+TEST(CanonicalQueryTest, IsValidNaturalSortNaturalHintDifferentDirections) {
+ const bool isExplain = false;
+ auto lpq = assertGet(LiteParsedQuery::makeFromFindCommand(
+ nss, fromjson("{find: 'testcoll', sort: {$natural: 1}, hint: {$natural: -1}}"), isExplain));
+
+ // Invalid: {$natural: 1} sort order and {$natural: -1} hint.
+ ASSERT_NOT_OK(isValid("{}", *lpq));
+}
+
//
// Tests for CanonicalQuery::sortTree
//