diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-06-22 16:55:04 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-07-13 16:53:12 -0400 |
commit | a6cc94d141f13feff33178a769c81282c7bc0170 (patch) | |
tree | 1a043a3718c54e8522f8b9bf0932c8d7f96ae79f /src/mongo/db/dbdirectclient.cpp | |
parent | 8204c7dacf17851057dda165e6d1638cbff70cbf (diff) | |
download | mongo-a6cc94d141f13feff33178a769c81282c7bc0170.tar.gz |
SERVER-29731 Unify logic around directly invoking a command
Diffstat (limited to 'src/mongo/db/dbdirectclient.cpp')
-rw-r--r-- | src/mongo/db/dbdirectclient.cpp | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp index b85be86dd0d..6609d69a642 100644 --- a/src/mongo/db/dbdirectclient.cpp +++ b/src/mongo/db/dbdirectclient.cpp @@ -164,23 +164,12 @@ unsigned long long DBDirectClient::count( BSONObj cmdObj = _countCmd(ns, query, options, limit, skip); NamespaceString nsString(ns); - std::string dbname = nsString.db().toString(); - - Command* countCmd = Command::findCommand("count"); - invariant(countCmd); - - std::string errmsg; - BSONObjBuilder result; - bool runRetval = countCmd->run(_opCtx, dbname, cmdObj, errmsg, result); - if (!runRetval) { - Command::appendCommandStatus(result, runRetval, errmsg); - Status commandStatus = getStatusFromCommandResult(result.obj()); - invariant(!commandStatus.isOK()); - uassertStatusOK(commandStatus); - } - BSONObj resultObj = result.obj(); - return static_cast<unsigned long long>(resultObj["n"].numberLong()); + auto result = Command::runCommandDirectly( + _opCtx, OpMsgRequest::fromDBAndBody(nsString.db(), std::move(cmdObj))); + + uassertStatusOK(getStatusFromCommandResult(result)); + return static_cast<unsigned long long>(result["n"].numberLong()); } } // namespace mongo |