diff options
author | David Storch <david.storch@10gen.com> | 2015-07-29 16:23:17 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-07-31 11:08:02 -0400 |
commit | 51dee2bfc2b043e2de166ff4b05379cadb997f0e (patch) | |
tree | 6e1315a1859960a7116d757d71333d3947e163c2 /src/mongo/db/query | |
parent | 157475b5b057d54440f97d144a551f5c16c70501 (diff) | |
download | mongo-51dee2bfc2b043e2de166ff4b05379cadb997f0e.tar.gz |
SERVER-19609 add shard version as a decoration on OperationContext
This will be useful when mongos starts sending shard version as a find command parameter.
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r-- | src/mongo/db/query/lite_parsed_query.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/query/lite_parsed_query_test.cpp | 8 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/mongo/db/query/lite_parsed_query.cpp b/src/mongo/db/query/lite_parsed_query.cpp index b82ba259257..c9422bc96c1 100644 --- a/src/mongo/db/query/lite_parsed_query.cpp +++ b/src/mongo/db/query/lite_parsed_query.cpp @@ -92,6 +92,8 @@ const char kNoCursorTimeoutField[] = "noCursorTimeout"; const char kAwaitDataField[] = "awaitData"; const char kPartialField[] = "partial"; const char kTermField[] = "term"; +const char kOptionsField[] = "options"; +const char kShardVersionField[] = "shardVersion"; } // namespace @@ -318,7 +320,7 @@ StatusWith<unique_ptr<LiteParsedQuery>> LiteParsedQuery::makeFromFindCommand(Nam } pq->_partial = el.boolean(); - } else if (str::equals(fieldName, "options")) { + } else if (str::equals(fieldName, kOptionsField)) { // 3.0.x versions of the shell may generate an explain of a find command with an // 'options' field. We accept this only if the 'options' field is empty so that // the shell's explain implementation is forwards compatible. @@ -326,7 +328,8 @@ StatusWith<unique_ptr<LiteParsedQuery>> LiteParsedQuery::makeFromFindCommand(Nam // TODO: Remove for 3.4. if (!pq->isExplain()) { return Status(ErrorCodes::FailedToParse, - "Field 'options' is only allowed for explain."); + str::stream() << "Field '" << kOptionsField + << "' is only allowed for explain."); } Status status = checkFieldType(el, Object); @@ -338,12 +341,13 @@ StatusWith<unique_ptr<LiteParsedQuery>> LiteParsedQuery::makeFromFindCommand(Nam if (!optionsObj.isEmpty()) { return Status(ErrorCodes::FailedToParse, str::stream() << "Failed to parse options: " << optionsObj.toString() - << ". " - << "You may need to update your shell or driver."); + << ". You may need to update your shell or driver."); } } else if (str::equals(fieldName, repl::ReadConcernArgs::kReadConcernFieldName.c_str())) { // read concern parsing is handled elsewhere. continue; + } else if (str::equals(fieldName, kShardVersionField)) { + // Shard version parsing is handled elsewhere. } else if (str::equals(fieldName, kTermField)) { Status status = checkFieldType(el, NumberLong); if (!status.isOK()) { diff --git a/src/mongo/db/query/lite_parsed_query_test.cpp b/src/mongo/db/query/lite_parsed_query_test.cpp index 238e8c7e6c8..05909fd4388 100644 --- a/src/mongo/db/query/lite_parsed_query_test.cpp +++ b/src/mongo/db/query/lite_parsed_query_test.cpp @@ -1049,6 +1049,14 @@ TEST(LiteParsedQueryTest, ParseCommandFirstFieldNotString) { ASSERT_NOT_OK(result.getStatus()); } +TEST(LiteParsedQueryTest, ParseCommandIgnoreShardVersionField) { + BSONObj cmdObj = fromjson("{find: 'test.testns', shardVersion: 'foo'}"); + const NamespaceString nss("test.testns"); + bool isExplain = false; + auto result = LiteParsedQuery::makeFromFindCommand(nss, cmdObj, isExplain); + ASSERT_OK(result.getStatus()); +} + TEST(LiteParsedQueryTest, DefaultQueryParametersCorrect) { BSONObj cmdObj = fromjson("{find: 'testns'}"); |