summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRandolph Tan <randolph@10gen.com>2015-06-18 10:21:42 -0400
committerRandolph Tan <randolph@10gen.com>2015-06-18 16:11:12 -0400
commitcffb338a1b4a07ce1c4207f7672dff589c607eee (patch)
tree0ede6657a0d67a16a583537a53a025e0260dd32b /src
parent9a86ae5e96c20c722dd82649c80ece45b4d457ff (diff)
downloadmongo-cffb338a1b4a07ce1c4207f7672dff589c607eee.tar.gz
SERVER-18589 Create LiteParseQuery factory for find cmd
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/query/canonical_query.cpp48
-rw-r--r--src/mongo/db/query/canonical_query_test.cpp216
-rw-r--r--src/mongo/db/query/lite_parsed_query.cpp100
-rw-r--r--src/mongo/db/query/lite_parsed_query.h48
-rw-r--r--src/mongo/db/query/lite_parsed_query_test.cpp349
-rw-r--r--src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp2
6 files changed, 415 insertions, 348 deletions
diff --git a/src/mongo/db/query/canonical_query.cpp b/src/mongo/db/query/canonical_query.cpp
index 4a68c34e7c5..67f753e0591 100644
--- a/src/mongo/db/query/canonical_query.cpp
+++ b/src/mongo/db/query/canonical_query.cpp
@@ -244,18 +244,18 @@ namespace {
// 0, 0, 0 is 'ntoskip', 'ntoreturn', and 'queryoptions'
// false, false is 'snapshot' and 'explain'
- auto lpqStatus = LiteParsedQuery::make(baseQuery.ns(),
- 0,
- 0,
- 0,
- baseQuery.getParsed().getFilter(),
- baseQuery.getParsed().getProj(),
- baseQuery.getParsed().getSort(),
- emptyObj,
- emptyObj,
- emptyObj,
- false,
- false);
+ auto lpqStatus = LiteParsedQuery::makeAsOpQuery(baseQuery.ns(),
+ 0,
+ 0,
+ 0,
+ baseQuery.getParsed().getFilter(),
+ baseQuery.getParsed().getProj(),
+ baseQuery.getParsed().getSort(),
+ emptyObj,
+ emptyObj,
+ emptyObj,
+ false,
+ false);
if (!lpqStatus.isOK()) {
return lpqStatus.getStatus();
}
@@ -287,18 +287,18 @@ namespace {
// Pass empty sort and projection.
BSONObj emptyObj;
- auto lpqStatus = LiteParsedQuery::make(ns,
- skip,
- limit,
- 0,
- query,
- proj,
- sort,
- hint,
- minObj,
- maxObj,
- snapshot,
- explain);
+ auto lpqStatus = LiteParsedQuery::makeAsOpQuery(ns,
+ skip,
+ limit,
+ 0,
+ query,
+ proj,
+ sort,
+ hint,
+ minObj,
+ maxObj,
+ snapshot,
+ explain);
if (!lpqStatus.isOK()) {
return lpqStatus.getStatus();
}
diff --git a/src/mongo/db/query/canonical_query_test.cpp b/src/mongo/db/query/canonical_query_test.cpp
index d770fd33977..14797c91ab3 100644
--- a/src/mongo/db/query/canonical_query_test.cpp
+++ b/src/mongo/db/query/canonical_query_test.cpp
@@ -101,18 +101,18 @@ namespace {
// Passes in default values for LiteParsedQuery.
// Filter inside LiteParsedQuery is not used.
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
// Valid: regular TEXT.
ASSERT_OK(isValid("{$text: {$search: 's'}}", *lpq));
@@ -173,18 +173,18 @@ namespace {
// Passes in default values for LiteParsedQuery.
// Filter inside LiteParsedQuery is not used.
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
// Valid: regular GEO_NEAR.
ASSERT_OK(isValid("{a: {$near: [0, 0]}}", *lpq));
@@ -257,18 +257,18 @@ namespace {
// Passes in default values for LiteParsedQuery.
// Filter inside LiteParsedQuery is not used.
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
// Invalid: TEXT and GEO_NEAR.
ASSERT_NOT_OK(isValid("{$text: {$search: 's'}, a: {$near: [0, 0]}}", *lpq));
@@ -292,18 +292,18 @@ namespace {
// Filter inside LiteParsedQuery is not used.
BSONObj sort = fromjson("{$natural: 1}");
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- sort,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ sort,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
// Invalid: TEXT and {$natural: 1} sort order.
ASSERT_NOT_OK(isValid("{$text: {$search: 's'}}", *lpq));
@@ -314,18 +314,18 @@ namespace {
// Filter inside LiteParsedQuery is not used.
BSONObj sort = fromjson("{$natural: -1}");
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- sort,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ sort,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
// Invalid: TEXT and {$natural: -1} sort order.
ASSERT_NOT_OK(isValid("{$text: {$search: 's'}}", *lpq));
@@ -336,18 +336,18 @@ namespace {
// Filter inside LiteParsedQuery is not used.
BSONObj hint = fromjson("{a: 1}");
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- hint,
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ hint,
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
// Invalid: TEXT and {$natural: -1} sort order.
ASSERT_NOT_OK(isValid("{$text: {$search: 's'}}", *lpq));
@@ -359,18 +359,18 @@ namespace {
// Filter inside LiteParsedQuery is not used.
BSONObj sort = fromjson("{$natural: 1}");
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- sort,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ sort,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
// Invalid: GEO_NEAR and {$natural: 1} sort order.
ASSERT_NOT_OK(isValid("{a: {$near: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}",
@@ -383,18 +383,18 @@ namespace {
// Filter inside LiteParsedQuery is not used.
BSONObj hint = fromjson("{$natural: 1}");
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- hint,
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ hint,
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
// Invalid: GEO_NEAR and {$natural: 1} hint.
ASSERT_NOT_OK(isValid("{a: {$near: {$geometry: {type: 'Point', coordinates: [0, 0]}}}}",
@@ -406,18 +406,18 @@ namespace {
// Filter inside LiteParsedQuery is not used.
bool snapshot = true;
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make(ns,
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- snapshot,
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery(ns,
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ snapshot,
+ false))); // explain
// Invalid: TEXT and snapshot.
ASSERT_NOT_OK(isValid("{$text: {$search: 's'}}", *lpq));
diff --git a/src/mongo/db/query/lite_parsed_query.cpp b/src/mongo/db/query/lite_parsed_query.cpp
index c508d7d6565..64a48a33a03 100644
--- a/src/mongo/db/query/lite_parsed_query.cpp
+++ b/src/mongo/db/query/lite_parsed_query.cpp
@@ -371,19 +371,9 @@ namespace {
}
}
- // We might need to update the projection object with a $meta projection.
- if (pq->returnKey()) {
- pq->addReturnKeyMetaProj();
- }
- if (pq->showRecordId()) {
- pq->addShowRecordIdMetaProj();
- }
+ pq->addMetaProjection();
- if (pq->isAwaitData() && !pq->isTailable()) {
- return Status(ErrorCodes::BadValue, "Cannot set awaitData without tailable");
- }
-
- Status validateStatus = pq->validate();
+ Status validateStatus = pq->validateFindCmd();
if (!validateStatus.isOK()) {
return validateStatus;
}
@@ -392,36 +382,18 @@ namespace {
}
// static
- StatusWith<unique_ptr<LiteParsedQuery>> LiteParsedQuery::make(const std::string& ns,
- int ntoreturn,
- const BSONObj& query) {
- return make(ns,
- 0, // ntoskip
- ntoreturn,
- 0, // query options
- query,
- BSONObj(), // proj
- BSONObj(), // sort
- BSONObj(), // hint
- BSONObj(), // minObj
- BSONObj(), // maxObj
- false, // snapshot
- false); // explain
- }
-
- // static
- StatusWith<unique_ptr<LiteParsedQuery>> LiteParsedQuery::make(const string& ns,
- int ntoskip,
- int ntoreturn,
- int queryOptions,
- const BSONObj& query,
- const BSONObj& proj,
- const BSONObj& sort,
- const BSONObj& hint,
- const BSONObj& minObj,
- const BSONObj& maxObj,
- bool snapshot,
- bool explain) {
+ StatusWith<unique_ptr<LiteParsedQuery>> LiteParsedQuery::makeAsOpQuery(const string& ns,
+ int ntoskip,
+ int ntoreturn,
+ int queryOptions,
+ const BSONObj& query,
+ const BSONObj& proj,
+ const BSONObj& sort,
+ const BSONObj& hint,
+ const BSONObj& minObj,
+ const BSONObj& maxObj,
+ bool snapshot,
+ bool explain) {
unique_ptr<LiteParsedQuery> pq(new LiteParsedQuery());
pq->_sort = sort.getOwned();
pq->_hint = hint.getOwned();
@@ -438,6 +410,31 @@ namespace {
return std::move(pq);
}
+ // static
+ StatusWith<unique_ptr<LiteParsedQuery>> LiteParsedQuery::makeAsFindCmd(const std::string& ns,
+ const BSONObj& query,
+ int limit) {
+ unique_ptr<LiteParsedQuery> pq(new LiteParsedQuery());
+
+ pq->_ns = ns;
+ pq->_filter = query.getOwned();
+
+ if (limit <= 0) {
+ return Status(ErrorCodes::BadValue, "limit value must be positive");
+ }
+
+ pq->_limit = limit;
+
+ pq->addMetaProjection();
+
+ Status validateStatus = pq->validateFindCmd();
+ if (!validateStatus.isOK()) {
+ return validateStatus;
+ }
+
+ return std::move(pq);
+ }
+
BSONObj LiteParsedQuery::asFindCommand() const {
BSONObjBuilder bob;
@@ -938,4 +935,23 @@ namespace {
_partial = (options & QueryOption_PartialResults) != 0;
}
+ void LiteParsedQuery::addMetaProjection() {
+ // We might need to update the projection object with a $meta projection.
+ if (returnKey()) {
+ addReturnKeyMetaProj();
+ }
+
+ if (showRecordId()) {
+ addShowRecordIdMetaProj();
+ }
+ }
+
+ Status LiteParsedQuery::validateFindCmd() {
+ if (isAwaitData() && !isTailable()) {
+ return Status(ErrorCodes::BadValue, "Cannot set awaitData without tailable");
+ }
+
+ return validate();
+ }
+
} // namespace mongo
diff --git a/src/mongo/db/query/lite_parsed_query.h b/src/mongo/db/query/lite_parsed_query.h
index 9623805d631..19fa8722af9 100644
--- a/src/mongo/db/query/lite_parsed_query.h
+++ b/src/mongo/db/query/lite_parsed_query.h
@@ -57,24 +57,28 @@ namespace mongo {
bool isExplain);
/**
- * Short and long forms for constructing a new LiteParsedQuery.
+ * Constructs a LiteParseQuery object as though it is from a legacy QueryMessage.
*/
- static StatusWith<std::unique_ptr<LiteParsedQuery>> make(const std::string& ns,
- int ntoreturn,
- const BSONObj& query);
-
- static StatusWith<std::unique_ptr<LiteParsedQuery>> make(const std::string& ns,
- int ntoskip,
- int ntoreturn,
- int queryoptions,
- const BSONObj& query,
- const BSONObj& proj,
- const BSONObj& sort,
- const BSONObj& hint,
- const BSONObj& minObj,
- const BSONObj& maxObj,
- bool snapshot,
- bool explain);
+ static StatusWith<std::unique_ptr<LiteParsedQuery>> makeAsOpQuery(const std::string& ns,
+ int ntoskip,
+ int ntoreturn,
+ int queryoptions,
+ const BSONObj& query,
+ const BSONObj& proj,
+ const BSONObj& sort,
+ const BSONObj& hint,
+ const BSONObj& minObj,
+ const BSONObj& maxObj,
+ bool snapshot,
+ bool explain);
+
+ /**
+ * Constructs a LiteParseQuery object that can be used to serialize to find command
+ * BSON object.
+ */
+ static StatusWith<std::unique_ptr<LiteParsedQuery>> makeAsFindCmd(const std::string& ns,
+ const BSONObj& query,
+ int limit);
/**
* Converts this LPQ into a find command.
@@ -219,6 +223,16 @@ namespace mongo {
*/
void initFromInt(int options);
+ /**
+ * Add the meta projection to this object if needed.
+ */
+ void addMetaProjection();
+
+ /**
+ * Returns OK if this is valid in the find command context.
+ */
+ Status validateFindCmd();
+
std::string _ns;
BSONObj _filter;
diff --git a/src/mongo/db/query/lite_parsed_query_test.cpp b/src/mongo/db/query/lite_parsed_query_test.cpp
index d31d0501b7e..4af9c8bc884 100644
--- a/src/mongo/db/query/lite_parsed_query_test.cpp
+++ b/src/mongo/db/query/lite_parsed_query_test.cpp
@@ -42,69 +42,69 @@ namespace {
using unittest::assertGet;
TEST(LiteParsedQueryTest, InitSortOrder) {
- ASSERT_OK(LiteParsedQuery::make("testns",
- 0,
- 1,
- 0,
- BSONObj(),
- BSONObj(),
- fromjson("{a: 1}"),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false) // explain
+ ASSERT_OK(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 1,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ fromjson("{a: 1}"),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false) // explain
.getStatus());
}
TEST(LiteParsedQueryTest, InitSortOrderString) {
- ASSERT_NOT_OK(LiteParsedQuery::make("testns",
- 0,
- 1,
- 0,
- BSONObj(),
- BSONObj(),
- fromjson("{a: \"\"}"),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false) // explain
+ ASSERT_NOT_OK(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 1,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ fromjson("{a: \"\"}"),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false) // explain
.getStatus());
}
TEST(LiteParsedQueryTest, GetFilter) {
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make("testns",
- 5,
- 6,
- 9,
- BSON("x" << 5),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery("testns",
+ 5,
+ 6,
+ 9,
+ BSON("x" << 5),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
ASSERT_EQUALS(BSON("x" << 5 ), lpq->getFilter());
}
TEST(LiteParsedQueryTest, NumToReturn) {
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make("testns",
- 5,
- 6,
- 9,
- BSON("x" << 5),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery("testns",
+ 5,
+ 6,
+ 9,
+ BSON("x" << 5),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
ASSERT_EQUALS(6, lpq->getBatchSize());
ASSERT(lpq->wantMore());
@@ -112,68 +112,68 @@ namespace {
TEST(LiteParsedQueryTest, NumToReturnNegative) {
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make("testns",
- 5,
- -6,
- 9,
- BSON("x" << 5),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery("testns",
+ 5,
+ -6,
+ 9,
+ BSON("x" << 5),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
ASSERT_EQUALS(6, lpq->getBatchSize());
ASSERT(!lpq->wantMore());
}
TEST(LiteParsedQueryTest, MinFieldsNotPrefixOfMax) {
- ASSERT_NOT_OK(LiteParsedQuery::make("testns",
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- fromjson("{a: 1}"),
- fromjson("{b: 1}"),
- false, // snapshot
- false) // explain
+ ASSERT_NOT_OK(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ fromjson("{a: 1}"),
+ fromjson("{b: 1}"),
+ false, // snapshot
+ false) // explain
.getStatus());
}
TEST(LiteParsedQueryTest, MinFieldsMoreThanMax) {
- ASSERT_NOT_OK(LiteParsedQuery::make("testns",
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- fromjson("{a: 1, b: 1}"),
- fromjson("{a: 1}"),
- false, // snapshot
- false) // explain
+ ASSERT_NOT_OK(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ fromjson("{a: 1, b: 1}"),
+ fromjson("{a: 1}"),
+ false, // snapshot
+ false) // explain
.getStatus());
}
TEST(LiteParsedQueryTest, MinFieldsLessThanMax) {
- ASSERT_NOT_OK(LiteParsedQuery::make("testns",
- 0,
- 0,
- 0,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- fromjson("{a: 1}"),
- fromjson("{a: 1, b: 1}"),
- false, // snapshot
- false) // explain
+ ASSERT_NOT_OK(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ fromjson("{a: 1}"),
+ fromjson("{a: 1, b: 1}"),
+ false, // snapshot
+ false) // explain
.getStatus());
}
@@ -184,18 +184,18 @@ namespace {
const BSONObj& sort) {
unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make("testns",
- 0,
- 0,
- 0,
- query,
- proj,
- sort,
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 0,
+ 0,
+ query,
+ proj,
+ sort,
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
}
//
@@ -213,18 +213,18 @@ namespace {
}
TEST(LiteParsedQueryTest, ForbidNonMetaSortOnFieldWithMetaProject) {
- ASSERT_NOT_OK(LiteParsedQuery::make("testns",
- 0,
- 0,
- 0,
- BSONObj(),
- fromjson("{a: {$meta: \"textScore\"}}"),
- fromjson("{a: 1}"),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false) // explain
+ ASSERT_NOT_OK(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ fromjson("{a: {$meta: \"textScore\"}}"),
+ fromjson("{a: 1}"),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false) // explain
.getStatus());
assertLiteParsedQuerySuccess(BSONObj(),
@@ -233,35 +233,72 @@ namespace {
}
TEST(LiteParsedQueryTest, ForbidMetaSortOnFieldWithoutMetaProject) {
- ASSERT_NOT_OK(LiteParsedQuery::make("testns",
- 0,
- 0,
- 0,
- BSONObj(),
- fromjson("{a: 1}"),
- fromjson("{a: {$meta: \"textScore\"}}"),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false) // explain
+ ASSERT_NOT_OK(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ fromjson("{a: 1}"),
+ fromjson("{a: {$meta: \"textScore\"}}"),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false) // explain
.getStatus());
- ASSERT_NOT_OK(LiteParsedQuery::make("testns",
- 0,
- 0,
- 0,
- BSONObj(),
- fromjson("{b: 1}"),
- fromjson("{a: {$meta: \"textScore\"}}"),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false) // explain
+ ASSERT_NOT_OK(LiteParsedQuery::makeAsOpQuery("testns",
+ 0,
+ 0,
+ 0,
+ BSONObj(),
+ fromjson("{b: 1}"),
+ fromjson("{a: {$meta: \"textScore\"}}"),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false) // explain
.getStatus());
}
+ TEST(LiteParsedQueryTest, MakeFindCmd) {
+ auto result = LiteParsedQuery::makeAsFindCmd("testns", BSON("x" << 1), 2);
+ ASSERT_OK(result.getStatus());
+
+ auto&& lpq = result.getValue();
+ ASSERT_EQUALS("testns", lpq->ns());
+ ASSERT_EQUALS(BSON("x" << 1), lpq->getFilter());
+ ASSERT_EQUALS(2, lpq->getLimit());
+
+ ASSERT_EQUALS(BSONObj(), lpq->getProj());
+ ASSERT_EQUALS(BSONObj(), lpq->getSort());
+ ASSERT_EQUALS(BSONObj(), lpq->getHint());
+ ASSERT_EQUALS(BSONObj(), lpq->getMin());
+ ASSERT_EQUALS(BSONObj(), lpq->getMax());
+
+ ASSERT_EQUALS(0, lpq->getSkip());
+ ASSERT_EQUALS(0, lpq->getMaxScan());
+ ASSERT_EQUALS(0, lpq->getMaxTimeMS());
+ ASSERT_EQUALS(0, lpq->getOptions());
+
+ ASSERT_FALSE(lpq->getBatchSize());
+
+ ASSERT_FALSE(lpq->fromFindCommand());
+ ASSERT_FALSE(lpq->isExplain());
+ ASSERT_FALSE(lpq->returnKey());
+ ASSERT_FALSE(lpq->showRecordId());
+ ASSERT_FALSE(lpq->isSnapshot());
+ ASSERT_FALSE(lpq->hasReadPref());
+ ASSERT_FALSE(lpq->isTailable());
+ ASSERT_FALSE(lpq->isSlaveOk());
+ ASSERT_FALSE(lpq->isOplogReplay());
+ ASSERT_FALSE(lpq->isNoCursorTimeout());
+ ASSERT_FALSE(lpq->isAwaitData());
+ ASSERT_FALSE(lpq->isExhaust());
+ ASSERT_FALSE(lpq->isPartial());
+ }
+
//
// Text meta BSON element validation
//
@@ -749,18 +786,18 @@ namespace {
TEST(LiteParsedQueryTest, ParseCommandNotFromFindCommand) {
std::unique_ptr<LiteParsedQuery> lpq(
- assertGet(LiteParsedQuery::make("testns",
- 5,
- 6,
- 9,
- BSON( "x" << 5 ),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- BSONObj(),
- false, // snapshot
- false))); // explain
+ assertGet(LiteParsedQuery::makeAsOpQuery("testns",
+ 5,
+ 6,
+ 9,
+ BSON( "x" << 5 ),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ BSONObj(),
+ false, // snapshot
+ false))); // explain
ASSERT(!lpq->fromFindCommand());
}
diff --git a/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp b/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp
index 6e26b0bc061..df265bf170f 100644
--- a/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp
+++ b/src/mongo/s/catalog/replset/catalog_manager_replica_set.cpp
@@ -456,7 +456,7 @@ namespace {
};
unique_ptr<LiteParsedQuery> findCmd(
- fassertStatusOK(28688, LiteParsedQuery::make(nss.toString(), limit, query)));
+ fassertStatusOK(28688, LiteParsedQuery::makeAsFindCmd(nss.toString(), query, limit)));
QueryFetcher fetcher(grid.shardRegistry()->getExecutor(),
host,