summaryrefslogtreecommitdiff
path: root/src/mongo/client/dbclient_cursor.cpp
diff options
context:
space:
mode:
authorMatthew Russotto <matthew.russotto@10gen.com>2018-08-23 17:04:14 -0400
committerMatthew Russotto <matthew.russotto@10gen.com>2018-08-23 17:04:14 -0400
commite7afdfb2941808f078cae1aafa05e40bdb079766 (patch)
tree350e0b035f6b145d094419e0a63bd67b91c391e3 /src/mongo/client/dbclient_cursor.cpp
parent84cabb97f967774645dcb9ea2581e3345a9b7547 (diff)
downloadmongo-e7afdfb2941808f078cae1aafa05e40bdb079766.tar.gz
SERVER-36094 Make query by UUID work for DBClient.
Diffstat (limited to 'src/mongo/client/dbclient_cursor.cpp')
-rw-r--r--src/mongo/client/dbclient_cursor.cpp22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/mongo/client/dbclient_cursor.cpp b/src/mongo/client/dbclient_cursor.cpp
index ff5698acc00..b16184c9700 100644
--- a/src/mongo/client/dbclient_cursor.cpp
+++ b/src/mongo/client/dbclient_cursor.cpp
@@ -111,14 +111,19 @@ Message DBClientCursor::_assembleInit() {
return assembleCommandRequest(_client, ns.db(), opts, query);
}
} else if (_useFindCommand) {
- auto qr = QueryRequest::fromLegacyQuery(ns,
+ // The caller supplies a 'query' object which may have $-prefixed directives in the format
+ // expected for a legacy OP_QUERY. Therefore, we use the legacy parsing code supplied by
+ // QueryRequest. When actually issuing the request to the remote node, we will assemble a
+ // find command.
+ auto qr = QueryRequest::fromLegacyQuery(_nsOrUuid,
query,
fieldsToReturn ? *fieldsToReturn : BSONObj(),
nToSkip,
nextBatchSize(),
opts);
if (qr.isOK() && !qr.getValue()->isExplain()) {
- BSONObj cmd = qr.getValue()->asFindCommand();
+ BSONObj cmd = _nsOrUuid.uuid() ? qr.getValue()->asFindCommandWithUuid()
+ : qr.getValue()->asFindCommand();
if (auto readPref = query["$readPreference"]) {
// QueryRequest doesn't handle $readPreference.
cmd = BSONObjBuilder(std::move(cmd)).append(readPref).obj();
@@ -126,6 +131,13 @@ Message DBClientCursor::_assembleInit() {
return assembleCommandRequest(_client, ns.db(), opts, std::move(cmd));
}
// else use legacy OP_QUERY request.
+ // Legacy OP_QUERY request does not support UUIDs.
+ if (_nsOrUuid.uuid()) {
+ // If there was a problem building the query request, report that.
+ uassertStatusOK(qr.getStatus());
+ // Otherwise it must have been explain.
+ uasserted(50937, "Query by UUID is not supported for explain queries.");
+ }
}
_useFindCommand = false; // Make sure we handle the reply correctly.
@@ -522,6 +534,7 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
: batch{std::move(initialBatch)},
_client(client),
_originalHost(_client->getServerAddress()),
+ _nsOrUuid(nsOrUuid),
ns(nsOrUuid.nss() ? *nsOrUuid.nss() : NamespaceString(nsOrUuid.dbname())),
_isCommand(ns.isCommand()),
query(query),
@@ -536,8 +549,11 @@ DBClientCursor::DBClientCursor(DBClientBase* client,
_ownCursor(true),
wasError(false),
_enabledBSONVersion(Validator<BSONObj>::enabledBSONVersion()) {
- if (queryOptions & QueryOptionLocal_forceOpQuery)
+ if (queryOptions & QueryOptionLocal_forceOpQuery) {
+ // Legacy OP_QUERY does not support UUIDs.
+ invariant(!_nsOrUuid.uuid());
_useFindCommand = false;
+ }
}
DBClientCursor::~DBClientCursor() {