summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorMartin Neupauer <martin.neupauer@mongodb.com>2018-08-09 17:09:08 -0400
committerMartin Neupauer <martin.neupauer@mongodb.com>2018-08-30 14:17:06 -0400
commit47306b9f203abee01f6fc54aa8d7ab8f8e25c8c9 (patch)
tree9d1734d0958b5f07afd6dad4adede420696fba3a /src/mongo/db/query
parentb46de3f6c06fab5cf9b7ea0f4176b32ff544a4bf (diff)
downloadmongo-47306b9f203abee01f6fc54aa8d7ab8f8e25c8c9.tar.gz
SERVER-35905 Plug pieces together to perform a distributed when applicable
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/cursor_response.cpp26
-rw-r--r--src/mongo/db/query/cursor_response.h6
2 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/db/query/cursor_response.cpp b/src/mongo/db/query/cursor_response.cpp
index 14b8af5e8f6..da7ef1127bc 100644
--- a/src/mongo/db/query/cursor_response.cpp
+++ b/src/mongo/db/query/cursor_response.cpp
@@ -39,6 +39,7 @@ namespace mongo {
namespace {
+const char kCursorsField[] = "cursors";
const char kCursorField[] = "cursor";
const char kIdField[] = "id";
const char kNsField[] = "ns";
@@ -129,6 +130,31 @@ CursorResponse::CursorResponse(NamespaceString nss,
_latestOplogTimestamp(latestOplogTimestamp),
_writeConcernError(std::move(writeConcernError)) {}
+std::vector<StatusWith<CursorResponse>> CursorResponse::parseFromBSONMany(
+ const BSONObj& cmdResponse) {
+ std::vector<StatusWith<CursorResponse>> cursors;
+ BSONElement cursorsElt = cmdResponse[kCursorsField];
+
+ // If there is not "cursors" array then treat it as a single cursor response
+ if (cursorsElt.type() != BSONType::Array) {
+ cursors.push_back(parseFromBSON(cmdResponse));
+ } else {
+ BSONObj cursorsObj = cursorsElt.embeddedObject();
+ for (BSONElement elt : cursorsObj) {
+ if (elt.type() != BSONType::Object) {
+ cursors.push_back({ErrorCodes::BadValue,
+ str::stream()
+ << "Cursors array element contains non-object element: "
+ << elt});
+ } else {
+ cursors.push_back(parseFromBSON(elt.Obj()));
+ }
+ }
+ }
+
+ return cursors;
+}
+
StatusWith<CursorResponse> CursorResponse::parseFromBSON(const BSONObj& cmdResponse) {
Status cmdStatus = getStatusFromCommandResult(cmdResponse);
if (!cmdStatus.isOK()) {
diff --git a/src/mongo/db/query/cursor_response.h b/src/mongo/db/query/cursor_response.h
index 529654118df..52f4d30ed6a 100644
--- a/src/mongo/db/query/cursor_response.h
+++ b/src/mongo/db/query/cursor_response.h
@@ -166,6 +166,12 @@ public:
};
/**
+ * Constructs a vector of CursorResponses from a command BSON response that represents one or
+ * more cursors.
+ */
+ static std::vector<StatusWith<CursorResponse>> parseFromBSONMany(const BSONObj& cmdResponse);
+
+ /**
* Constructs a CursorResponse from the command BSON response.
*/
static StatusWith<CursorResponse> parseFromBSON(const BSONObj& cmdResponse);