BSONObj CommandHelpers::runCommandDirectly(OperationContext* opCtx, const OpMsgRequest& request) {
    auto command = globalCommandRegistry()->findCommand(request.getCommandName());
    invariant(command);
    BufBuilder bb;
    CommandReplyBuilder crb(BSONObjBuilder{bb});
    try {
        auto invocation = command->parse(opCtx, request);
        invocation->run(opCtx, &crb);
        auto body = crb.getBodyBuilder();
        CommandHelpers::extractOrAppendOk(body);
    } catch (const StaleConfigException&) {
        // These exceptions are intended to be handled at a higher level.
        throw;
    } catch (const DBException& ex) {
        auto body = crb.getBodyBuilder();
        body.resetToEmpty();
        appendCommandStatusNoThrow(body, ex.toStatus());
    }
    return BSONObj(bb.release());
}
BSONObj CommandHelpers::runCommandDirectly(OperationContext* opCtx, const OpMsgRequest& request) {
    auto command = globalCommandRegistry()->findCommand(request.getCommandName());
    invariant(command);
    BufBuilder bb;
    CommandReplyBuilder crb(BSONObjBuilder{bb});
    try {
        auto invocation = command->parse(opCtx, request);
        invocation->run(opCtx, &crb);
        auto body = crb.getBodyBuilder();
        CommandHelpers::extractOrAppendOk(body);
    } catch (const StaleConfigException&) {
         
        throw;
    } catch (const DBException& ex) {
        auto body = crb.getBodyBuilder();
        body.resetToEmpty();
        appendCommandStatusNoThrow(body, ex.toStatus());
    }
    return BSONObj(bb.release());
}