summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-03-15 09:49:30 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2016-03-15 10:34:34 -0400
commitfea8935aa03a68524014e5d0697ca5e55d390a2b (patch)
treef426f50ffbd32ecb752165829662845e4f3e0623
parent65afd1db6fc3b6fdba053dc75117967d30d48feb (diff)
downloadmongo-fea8935aa03a68524014e5d0697ca5e55d390a2b.tar.gz
SERVER-23136 Count command should return InvalidNamespace instead of BadValue
-rw-r--r--src/mongo/db/query/count_request.cpp12
-rw-r--r--src/mongo/db/query/count_request.h2
-rw-r--r--src/mongo/db/query/count_request_test.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_count.cpp14
4 files changed, 16 insertions, 16 deletions
diff --git a/src/mongo/db/query/count_request.cpp b/src/mongo/db/query/count_request.cpp
index ad27d36c376..fec461455df 100644
--- a/src/mongo/db/query/count_request.cpp
+++ b/src/mongo/db/query/count_request.cpp
@@ -43,8 +43,8 @@ const char kHintField[] = "hint";
} // namespace
-CountRequest::CountRequest(const std::string& fullNs, BSONObj query)
- : _nss(fullNs), _query(query.getOwned()) {}
+CountRequest::CountRequest(NamespaceString nss, BSONObj query)
+ : _nss(std::move(nss)), _query(query.getOwned()) {}
void CountRequest::setHint(BSONObj hint) {
_hint = hint.getOwned();
@@ -76,13 +76,13 @@ StatusWith<CountRequest> CountRequest::parseFromBSON(const std::string& dbname,
BSONElement firstElt = cmdObj.firstElement();
const std::string coll = (firstElt.type() == BSONType::String) ? firstElt.str() : "";
- const std::string ns = str::stream() << dbname << "." << coll;
- if (!nsIsFull(ns)) {
- return Status(ErrorCodes::BadValue, "invalid collection name");
+ NamespaceString nss(dbname, coll);
+ if (!nss.isValid()) {
+ return Status(ErrorCodes::InvalidNamespace, "invalid collection name");
}
// We don't validate that "query" is a nested object due to SERVER-15456.
- CountRequest request(ns, cmdObj.getObjectField(kQueryField));
+ CountRequest request(std::move(nss), cmdObj.getObjectField(kQueryField));
// Limit
if (cmdObj[kLimitField].isNumber()) {
diff --git a/src/mongo/db/query/count_request.h b/src/mongo/db/query/count_request.h
index 781b06dd91f..5ea4c1b08d7 100644
--- a/src/mongo/db/query/count_request.h
+++ b/src/mongo/db/query/count_request.h
@@ -48,7 +48,7 @@ public:
/**
* Construct an empty request.
*/
- CountRequest(const std::string& fullNs, BSONObj query);
+ CountRequest(NamespaceString nss, BSONObj query);
const NamespaceString& getNs() const {
return _nss;
diff --git a/src/mongo/db/query/count_request_test.cpp b/src/mongo/db/query/count_request_test.cpp
index f16d32bf6d1..4df3fbffee7 100644
--- a/src/mongo/db/query/count_request_test.cpp
+++ b/src/mongo/db/query/count_request_test.cpp
@@ -98,7 +98,7 @@ TEST(CountRequest, FailParseMissingNS) {
const auto countRequestStatus =
CountRequest::parseFromBSON("TestDB", BSON("query" << BSON("a" << BSON("$gte" << 11))));
- ASSERT_EQUALS(countRequestStatus.getStatus(), ErrorCodes::BadValue);
+ ASSERT_EQUALS(countRequestStatus.getStatus(), ErrorCodes::InvalidNamespace);
}
TEST(CountRequest, FailParseBadSkipValue) {
@@ -113,7 +113,7 @@ TEST(CountRequest, FailParseBadSkipValue) {
}
TEST(CountRequest, ToBSON) {
- CountRequest countRequest("TestDB.TestColl", BSON("a" << BSON("$gte" << 11)));
+ CountRequest countRequest(NamespaceString("TestDB.TestColl"), BSON("a" << BSON("$gte" << 11)));
countRequest.setLimit(100);
countRequest.setSkip(1000);
countRequest.setHint(BSON("b" << 5));
diff --git a/src/mongo/dbtests/query_stage_count.cpp b/src/mongo/dbtests/query_stage_count.cpp
index 45584db28f4..cfdcf6ffab8 100644
--- a/src/mongo/dbtests/query_stage_count.cpp
+++ b/src/mongo/dbtests/query_stage_count.cpp
@@ -234,7 +234,7 @@ protected:
class QueryStageCountNoChangeDuringYield : public CountStageTest {
public:
void run() {
- CountRequest request(ns(), BSON("x" << LT << kDocuments / 2));
+ CountRequest request(NamespaceString(ns()), BSON("x" << LT << kDocuments / 2));
testCount(request, kDocuments / 2);
testCount(request, kDocuments / 2, true);
@@ -244,7 +244,7 @@ public:
class QueryStageCountYieldWithSkip : public CountStageTest {
public:
void run() {
- CountRequest request(ns(), BSON("x" << GTE << 0));
+ CountRequest request(NamespaceString(ns()), BSON("x" << GTE << 0));
request.setSkip(2);
testCount(request, kDocuments - 2);
@@ -255,7 +255,7 @@ public:
class QueryStageCountYieldWithLimit : public CountStageTest {
public:
void run() {
- CountRequest request(ns(), BSON("x" << GTE << 0));
+ CountRequest request(NamespaceString(ns()), BSON("x" << GTE << 0));
request.setSkip(0);
request.setLimit(2);
@@ -268,7 +268,7 @@ public:
class QueryStageCountInsertDuringYield : public CountStageTest {
public:
void run() {
- CountRequest request(ns(), BSON("x" << 1));
+ CountRequest request(NamespaceString(ns()), BSON("x" << 1));
testCount(request, kInterjections + 1);
testCount(request, kInterjections + 1, true);
@@ -285,7 +285,7 @@ public:
void run() {
// expected count would be 99 but we delete the second record
// after doing the first unit of work
- CountRequest request(ns(), BSON("x" << GTE << 1));
+ CountRequest request(NamespaceString(ns()), BSON("x" << GTE << 1));
testCount(request, kDocuments - 2);
testCount(request, kDocuments - 2, true);
@@ -312,7 +312,7 @@ public:
void run() {
// expected count would be kDocuments-2 but we update the first and second records
// after doing the first unit of work so they wind up getting counted later on
- CountRequest request(ns(), BSON("x" << GTE << 2));
+ CountRequest request(NamespaceString(ns()), BSON("x" << GTE << 2));
testCount(request, kDocuments);
testCount(request, kDocuments, true);
@@ -335,7 +335,7 @@ public:
class QueryStageCountMultiKeyDuringYield : public CountStageTest {
public:
void run() {
- CountRequest request(ns(), BSON("x" << 1));
+ CountRequest request(NamespaceString(ns()), BSON("x" << 1));
testCount(request, kDocuments + 1, true); // only applies to indexed case
}