summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-07-13 09:27:56 -0400
committerMathias Stearn <mathias@10gen.com>2017-07-26 15:13:34 -0400
commit84ef4754b61003c63a480ac009fe2302970b00c9 (patch)
treea04948da01af49265a4ab366d79dc146b1e398a4 /src/mongo/db/query
parent8b36e1d65f4b1730e7fc6086a0e1f429e48ba695 (diff)
downloadmongo-84ef4754b61003c63a480ac009fe2302970b00c9.tar.gz
SERVER-28509 DBClientCursor now uses read commands
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/cursor_response.h4
-rw-r--r--src/mongo/db/query/query_request.cpp12
-rw-r--r--src/mongo/db/query/query_request.h12
-rw-r--r--src/mongo/db/query/query_request_test.cpp69
4 files changed, 83 insertions, 14 deletions
diff --git a/src/mongo/db/query/cursor_response.h b/src/mongo/db/query/cursor_response.h
index 2eed3db4901..9811c29b0ba 100644
--- a/src/mongo/db/query/cursor_response.h
+++ b/src/mongo/db/query/cursor_response.h
@@ -155,6 +155,10 @@ public:
return _batch;
}
+ std::vector<BSONObj> releaseBatch() {
+ return std::move(_batch);
+ }
+
boost::optional<long long> getNumReturnedSoFar() const {
return _numReturnedSoFar;
}
diff --git a/src/mongo/db/query/query_request.cpp b/src/mongo/db/query/query_request.cpp
index 2bf9f12a15c..6e4d0745b2a 100644
--- a/src/mongo/db/query/query_request.cpp
+++ b/src/mongo/db/query/query_request.cpp
@@ -726,12 +726,12 @@ StatusWith<unique_ptr<QueryRequest>> QueryRequest::fromLegacyQueryMessage(const
return std::move(qr);
}
-StatusWith<unique_ptr<QueryRequest>> QueryRequest::fromLegacyQueryForTest(NamespaceString nss,
- const BSONObj& queryObj,
- const BSONObj& proj,
- int ntoskip,
- int ntoreturn,
- int queryOptions) {
+StatusWith<unique_ptr<QueryRequest>> QueryRequest::fromLegacyQuery(NamespaceString nss,
+ const BSONObj& queryObj,
+ const BSONObj& proj,
+ int ntoskip,
+ int ntoreturn,
+ int queryOptions) {
auto qr = stdx::make_unique<QueryRequest>(nss);
Status status = qr->init(ntoskip, ntoreturn, queryOptions, queryObj, proj, true);
diff --git a/src/mongo/db/query/query_request.h b/src/mongo/db/query/query_request.h
index a8ca956c43b..620e50d8804 100644
--- a/src/mongo/db/query/query_request.h
+++ b/src/mongo/db/query/query_request.h
@@ -404,12 +404,12 @@ public:
/**
* Parse the provided legacy query object and parameters to construct a QueryRequest.
*/
- static StatusWith<std::unique_ptr<QueryRequest>> fromLegacyQueryForTest(NamespaceString nss,
- const BSONObj& queryObj,
- const BSONObj& proj,
- int ntoskip,
- int ntoreturn,
- int queryOptions);
+ static StatusWith<std::unique_ptr<QueryRequest>> fromLegacyQuery(NamespaceString nss,
+ const BSONObj& queryObj,
+ const BSONObj& proj,
+ int ntoskip,
+ int ntoreturn,
+ int queryOptions);
private:
Status init(int ntoskip,
diff --git a/src/mongo/db/query/query_request_test.cpp b/src/mongo/db/query/query_request_test.cpp
index f64a5429faf..4910b769af9 100644
--- a/src/mongo/db/query/query_request_test.cpp
+++ b/src/mongo/db/query/query_request_test.cpp
@@ -32,6 +32,7 @@
#include <boost/optional.hpp>
#include <boost/optional/optional_io.hpp>
+#include "mongo/db/dbmessage.h"
#include "mongo/db/json.h"
#include "mongo/db/namespace_string.h"
#include "mongo/db/pipeline/aggregation_request.h"
@@ -1336,10 +1337,11 @@ TEST(QueryRequestTest, ParseFromLegacyObjMetaOpComment) {
"$comment: {b: 2, c: {d: 'ParseFromLegacyObjMetaOpComment'}}}");
const NamespaceString nss("test.testns");
unique_ptr<QueryRequest> qr(
- assertGet(QueryRequest::fromLegacyQueryForTest(nss, queryObj, BSONObj(), 0, 0, 0)));
+ assertGet(QueryRequest::fromLegacyQuery(nss, queryObj, BSONObj(), 0, 0, 0)));
// Ensure that legacy comment meta-operator is parsed to a string comment
ASSERT_EQ(qr->getComment(), "{ b: 2, c: { d: \"ParseFromLegacyObjMetaOpComment\" } }");
+ ASSERT_BSONOBJ_EQ(qr->getFilter(), fromjson("{a: 1}"));
}
TEST(QueryRequestTest, ParseFromLegacyStringMetaOpComment) {
@@ -1348,9 +1350,72 @@ TEST(QueryRequestTest, ParseFromLegacyStringMetaOpComment) {
"$comment: 'ParseFromLegacyStringMetaOpComment'}");
const NamespaceString nss("test.testns");
unique_ptr<QueryRequest> qr(
- assertGet(QueryRequest::fromLegacyQueryForTest(nss, queryObj, BSONObj(), 0, 0, 0)));
+ assertGet(QueryRequest::fromLegacyQuery(nss, queryObj, BSONObj(), 0, 0, 0)));
ASSERT_EQ(qr->getComment(), "ParseFromLegacyStringMetaOpComment");
+ ASSERT_BSONOBJ_EQ(qr->getFilter(), fromjson("{a: 1}"));
+}
+
+TEST(QueryRequestTest, ParseFromLegacyQuery) {
+ const auto kSkip = 1;
+ const auto kNToReturn = 2;
+
+ BSONObj queryObj = fromjson(R"({
+ query: {query: 1},
+ orderby: {sort: 1},
+ $hint: {hint: 1},
+ $explain: false,
+ $min: {x: 'min'},
+ $max: {x: 'max'},
+ $maxScan: 7
+ })");
+ const NamespaceString nss("test.testns");
+ unique_ptr<QueryRequest> qr(assertGet(QueryRequest::fromLegacyQuery(
+ nss, queryObj, BSON("proj" << 1), kSkip, kNToReturn, QueryOption_Exhaust)));
+
+ ASSERT_EQ(qr->nss(), nss);
+ ASSERT_BSONOBJ_EQ(qr->getFilter(), fromjson("{query: 1}"));
+ ASSERT_BSONOBJ_EQ(qr->getProj(), fromjson("{proj: 1}"));
+ ASSERT_BSONOBJ_EQ(qr->getSort(), fromjson("{sort: 1}"));
+ ASSERT_BSONOBJ_EQ(qr->getHint(), fromjson("{hint: 1}"));
+ ASSERT_BSONOBJ_EQ(qr->getMin(), fromjson("{x: 'min'}"));
+ ASSERT_BSONOBJ_EQ(qr->getMax(), fromjson("{x: 'max'}"));
+ ASSERT_EQ(qr->getSkip(), boost::optional<long long>(kSkip));
+ ASSERT_EQ(qr->getNToReturn(), boost::optional<long long>(kNToReturn));
+ ASSERT_EQ(qr->wantMore(), true);
+ ASSERT_EQ(qr->isExplain(), false);
+ ASSERT_EQ(qr->getMaxScan(), 7);
+ ASSERT_EQ(qr->isSlaveOk(), false);
+ ASSERT_EQ(qr->isOplogReplay(), false);
+ ASSERT_EQ(qr->isNoCursorTimeout(), false);
+ ASSERT_EQ(qr->isAwaitData(), false);
+ ASSERT_EQ(qr->isExhaust(), true);
+ ASSERT_EQ(qr->isAllowPartialResults(), false);
+ ASSERT_EQ(qr->getOptions(), QueryOption_Exhaust);
+}
+
+TEST(QueryRequestTest, ParseFromLegacyQueryUnwrapped) {
+ BSONObj queryObj = fromjson(R"({
+ foo: 1
+ })");
+ const NamespaceString nss("test.testns");
+ unique_ptr<QueryRequest> qr(assertGet(
+ QueryRequest::fromLegacyQuery(nss, queryObj, BSONObj(), 0, 0, QueryOption_Exhaust)));
+
+ ASSERT_EQ(qr->nss(), nss);
+ ASSERT_BSONOBJ_EQ(qr->getFilter(), fromjson("{foo: 1}"));
+}
+
+TEST(QueryRequestTest, ParseFromLegacyQueryTooNegativeNToReturn) {
+ BSONObj queryObj = fromjson(R"({
+ foo: 1
+ })");
+ const NamespaceString nss("test.testns");
+
+ ASSERT_NOT_OK(
+ QueryRequest::fromLegacyQuery(
+ nss, queryObj, BSONObj(), 0, std::numeric_limits<int>::min(), QueryOption_Exhaust)
+ .getStatus());
}
} // namespace mongo