summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorSophia Tan <sophia_tll@hotmail.com>2023-01-23 16:23:20 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-23 18:12:53 +0000
commit056b0578ea08a530dbee00986c0f4a651771628a (patch)
tree2f75472d62f86b9c2d117e5531f8ea5e2a720887 /src/mongo/db
parent368ae38dea1386062c6c7a1591c469c7bc9d56fe (diff)
downloadmongo-056b0578ea08a530dbee00986c0f4a651771628a.tar.gz
SERVER-72948 Change DBClient runCommand function to use DatabaseName object
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/commands/analyze_cmd.cpp2
-rw-r--r--src/mongo/db/commands/create_indexes_test.cpp2
-rw-r--r--src/mongo/db/commands/external_data_source_commands_test.cpp6
-rw-r--r--src/mongo/db/commands/feature_compatibility_version.cpp2
-rw-r--r--src/mongo/db/keys_collection_cache_test.cpp4
-rw-r--r--src/mongo/db/pipeline/aggregation_request_helper.cpp8
-rw-r--r--src/mongo/db/pipeline/aggregation_request_helper.h2
-rw-r--r--src/mongo/db/pipeline/aggregation_request_test.cpp4
-rw-r--r--src/mongo/db/repl/all_database_cloner.cpp4
-rw-r--r--src/mongo/db/repl/collection_cloner.cpp2
-rw-r--r--src/mongo/db/repl/initial_sync_base_cloner.cpp3
-rw-r--r--src/mongo/db/repl/isself.cpp2
-rw-r--r--src/mongo/db/repl/oplog_applier_impl_test.cpp10
-rw-r--r--src/mongo/db/repl/primary_only_service_test.cpp2
-rw-r--r--src/mongo/db/repl/rollback_source_impl.cpp3
-rw-r--r--src/mongo/db/repl/storage_timestamp_test.cpp10
-rw-r--r--src/mongo/db/repl/tenant_all_database_cloner.cpp9
-rw-r--r--src/mongo/db/repl/tenant_collection_cloner.cpp6
-rw-r--r--src/mongo/db/repl/tenant_database_cloner.cpp7
-rw-r--r--src/mongo/db/repl/tenant_migration_donor_service.cpp4
-rw-r--r--src/mongo/db/repl/tenant_migration_recipient_service.cpp5
-rw-r--r--src/mongo/db/s/add_shard_cmd.cpp3
-rw-r--r--src/mongo/db/s/config/sharding_catalog_manager.cpp6
-rw-r--r--src/mongo/db/s/create_collection_coordinator.cpp2
-rw-r--r--src/mongo/db/s/global_index/global_index_cloning_service_test.cpp3
-rw-r--r--src/mongo/db/s/global_index/global_index_inserter_test.cpp3
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp2
-rw-r--r--src/mongo/db/s/move_primary_coordinator.cpp2
-rw-r--r--src/mongo/db/s/move_primary_source_manager.cpp2
-rw-r--r--src/mongo/db/s/resharding/resharding_coordinator_service.cpp4
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp2
-rw-r--r--src/mongo/db/s/shard_key_util.cpp4
-rw-r--r--src/mongo/db/serverless/shard_split_donor_service.cpp4
-rw-r--r--src/mongo/db/session/sessions_collection.cpp6
-rw-r--r--src/mongo/db/session/sessions_collection_rs.cpp51
-rw-r--r--src/mongo/db/session/sessions_collection_standalone.cpp3
-rw-r--r--src/mongo/db/transaction/transaction_api.cpp2
-rw-r--r--src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp2
38 files changed, 103 insertions, 95 deletions
diff --git a/src/mongo/db/commands/analyze_cmd.cpp b/src/mongo/db/commands/analyze_cmd.cpp
index cad6d7c8b57..8461f923181 100644
--- a/src/mongo/db/commands/analyze_cmd.cpp
+++ b/src/mongo/db/commands/analyze_cmd.cpp
@@ -214,7 +214,7 @@ public:
// Run Aggregate
BSONObj analyzeResult;
- client.runCommand(nss.db().toString(),
+ client.runCommand(nss.dbName(),
analyzeCommandAsAggregationCommand(opCtx,
nss.db(),
nss.coll(),
diff --git a/src/mongo/db/commands/create_indexes_test.cpp b/src/mongo/db/commands/create_indexes_test.cpp
index b7977ef5e67..1477ab3dcb0 100644
--- a/src/mongo/db/commands/create_indexes_test.cpp
+++ b/src/mongo/db/commands/create_indexes_test.cpp
@@ -68,7 +68,7 @@ TEST_F(CreateIndexesTest, CreateIndexesFailsWhenIndexBuildsCollectionIsMissing)
"createIndexes" << nss.coll() << "indexes" << BSON_ARRAY(index) << "commitQuorum" << 0);
BSONObj result;
// This should fail since config.system.indexBuilds does not exist.
- ASSERT_FALSE(client.runCommand(nss.db().toString(), createIndexesCmdObj, result)) << result;
+ ASSERT_FALSE(client.runCommand(nss.dbName(), createIndexesCmdObj, result)) << result;
ASSERT(result.hasField("code"));
ASSERT_EQ(result.getIntField("code"), 6325700);
}
diff --git a/src/mongo/db/commands/external_data_source_commands_test.cpp b/src/mongo/db/commands/external_data_source_commands_test.cpp
index 5303c77e757..217773fa023 100644
--- a/src/mongo/db/commands/external_data_source_commands_test.cpp
+++ b/src/mongo/db/commands/external_data_source_commands_test.cpp
@@ -31,6 +31,7 @@
#include "mongo/bson/bsonobjbuilder.h"
#include "mongo/client/dbclient_cursor.h"
+#include "mongo/db/database_name.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/pipeline/aggregation_request_helper.h"
#include "mongo/db/query/query_knobs_gen.h"
@@ -132,9 +133,12 @@ protected:
ServiceContext::UniqueOperationContext _uniqueOpCtx{makeOperationContext()};
OperationContext* _opCtx{_uniqueOpCtx.get()};
- static constexpr auto kDatabaseName = "external_data_source";
+ static const DatabaseName kDatabaseName;
};
+const DatabaseName ExternalDataSourceCommandsTest::kDatabaseName =
+ DatabaseName(boost::none, "external_data_source");
+
TEST_F(ExternalDataSourceCommandsTest, SimpleScanAggRequest) {
const auto nDocs = _random.nextInt32(100) + 1;
std::vector<BSONObj> srcDocs = generateRandomSimpleDocs(nDocs);
diff --git a/src/mongo/db/commands/feature_compatibility_version.cpp b/src/mongo/db/commands/feature_compatibility_version.cpp
index dfa4471bacf..8c9f621f0c2 100644
--- a/src/mongo/db/commands/feature_compatibility_version.cpp
+++ b/src/mongo/db/commands/feature_compatibility_version.cpp
@@ -252,7 +252,7 @@ void runUpdateCommand(OperationContext* opCtx, const FeatureCompatibilityVersion
// Update the featureCompatibilityVersion document stored in the server configuration
// collection.
BSONObj updateResult;
- client.runCommand(nss.db().toString(), updateCmd.obj(), updateResult);
+ client.runCommand(nss.dbName(), updateCmd.obj(), updateResult);
uassertStatusOK(getStatusFromWriteCommandReply(updateResult));
}
diff --git a/src/mongo/db/keys_collection_cache_test.cpp b/src/mongo/db/keys_collection_cache_test.cpp
index 0e2f179000e..b260dbb82e9 100644
--- a/src/mongo/db/keys_collection_cache_test.cpp
+++ b/src/mongo/db/keys_collection_cache_test.cpp
@@ -93,7 +93,7 @@ protected:
DBDirectClient client(opCtx);
BSONObj result;
- client.runCommand(nss.db().toString(), cmdObj, result);
+ client.runCommand(nss.dbName(), cmdObj, result);
ASSERT_OK(getStatusFromWriteCommandReply(result));
}
@@ -114,7 +114,7 @@ protected:
DBDirectClient client(opCtx);
BSONObj result;
- client.runCommand(nss.db().toString(), cmdObj, result);
+ client.runCommand(nss.dbName(), cmdObj, result);
ASSERT_OK(getStatusFromWriteCommandReply(result));
}
diff --git a/src/mongo/db/pipeline/aggregation_request_helper.cpp b/src/mongo/db/pipeline/aggregation_request_helper.cpp
index 1af17053607..60f19b9cf2e 100644
--- a/src/mongo/db/pipeline/aggregation_request_helper.cpp
+++ b/src/mongo/db/pipeline/aggregation_request_helper.cpp
@@ -75,17 +75,13 @@ StatusWith<AggregateCommandRequest> parseFromBSONForTests(
}
StatusWith<AggregateCommandRequest> parseFromBSONForTests(
- const std::string& dbName,
+ const DatabaseName& dbName,
const BSONObj& cmdObj,
boost::optional<ExplainOptions::Verbosity> explainVerbosity,
bool apiStrict) {
try {
return parseFromBSON(
- /*opCtx=*/nullptr,
- DatabaseName(boost::none, dbName),
- cmdObj,
- explainVerbosity,
- apiStrict);
+ /*opCtx=*/nullptr, dbName, cmdObj, explainVerbosity, apiStrict);
} catch (const AssertionException&) {
return exceptionToStatus();
}
diff --git a/src/mongo/db/pipeline/aggregation_request_helper.h b/src/mongo/db/pipeline/aggregation_request_helper.h
index 7c7c7c2453c..dff875ff7f5 100644
--- a/src/mongo/db/pipeline/aggregation_request_helper.h
+++ b/src/mongo/db/pipeline/aggregation_request_helper.h
@@ -90,7 +90,7 @@ AggregateCommandRequest parseFromBSON(OperationContext* opCtx,
bool apiStrict);
StatusWith<AggregateCommandRequest> parseFromBSONForTests(
- const std::string& dbName,
+ const DatabaseName& dbName,
const BSONObj& cmdObj,
boost::optional<ExplainOptions::Verbosity> explainVerbosity = boost::none,
bool apiStrict = false);
diff --git a/src/mongo/db/pipeline/aggregation_request_test.cpp b/src/mongo/db/pipeline/aggregation_request_test.cpp
index f2512b6a1c0..ba75b6f28ca 100644
--- a/src/mongo/db/pipeline/aggregation_request_test.cpp
+++ b/src/mongo/db/pipeline/aggregation_request_test.cpp
@@ -699,8 +699,8 @@ TEST(AggregationRequestTest, ParseFromBSONOverloadsShouldProduceIdenticalRequest
"'a'}");
NamespaceString nss("a.collection");
- auto aggReqDBName =
- unittest::assertGet(aggregation_request_helper::parseFromBSONForTests("a", inputBSON));
+ auto aggReqDBName = unittest::assertGet(
+ aggregation_request_helper::parseFromBSONForTests(nss.dbName(), inputBSON));
auto aggReqNSS =
unittest::assertGet(aggregation_request_helper::parseFromBSONForTests(nss, inputBSON));
diff --git a/src/mongo/db/repl/all_database_cloner.cpp b/src/mongo/db/repl/all_database_cloner.cpp
index 12ba9a0c33f..399ad24f608 100644
--- a/src/mongo/db/repl/all_database_cloner.cpp
+++ b/src/mongo/db/repl/all_database_cloner.cpp
@@ -227,8 +227,6 @@ void AllDatabaseCloner::postStage() {
_stats.databaseStats.emplace_back();
_stats.databaseStats.back().dbname = dbName;
- auto db = DatabaseNameUtil::serialize(dbName);
-
BSONObj cmdObj = BSON("dbStats" << 1);
BSONObjBuilder b(cmdObj);
if (gMultitenancySupport &&
@@ -239,7 +237,7 @@ void AllDatabaseCloner::postStage() {
}
BSONObj res;
- getClient()->runCommand(db, b.obj(), res);
+ getClient()->runCommand(dbName, b.obj(), res);
// It is possible for the call to 'dbStats' to fail if the sync source contains invalid
// views. We should not fail initial sync in this case due to the situation where the
diff --git a/src/mongo/db/repl/collection_cloner.cpp b/src/mongo/db/repl/collection_cloner.cpp
index b8bd3ba7331..216eec53a0a 100644
--- a/src/mongo/db/repl/collection_cloner.cpp
+++ b/src/mongo/db/repl/collection_cloner.cpp
@@ -138,7 +138,7 @@ void CollectionCloner::preStage() {
}
BSONObj res;
- getClient()->runCommand(DatabaseNameUtil::serialize(_sourceNss.dbName()), b.obj(), res);
+ getClient()->runCommand(_sourceNss.dbName(), b.obj(), res);
if (auto status = getStatusFromCommandResult(res); status.isOK()) {
_stats.bytesToCopy = res.getField("size").safeNumberLong();
if (_stats.bytesToCopy > 0) {
diff --git a/src/mongo/db/repl/initial_sync_base_cloner.cpp b/src/mongo/db/repl/initial_sync_base_cloner.cpp
index cf979b02f9e..6f6888fe9ce 100644
--- a/src/mongo/db/repl/initial_sync_base_cloner.cpp
+++ b/src/mongo/db/repl/initial_sync_base_cloner.cpp
@@ -145,7 +145,8 @@ Status InitialSyncBaseCloner::checkInitialSyncIdIsUnchanged() {
Status InitialSyncBaseCloner::checkRollBackIdIsUnchanged() {
BSONObj info;
try {
- getClient()->runCommand("admin", BSON("replSetGetRBID" << 1), info);
+ getClient()->runCommand(
+ DatabaseName(boost::none, "admin"), BSON("replSetGetRBID" << 1), info);
} catch (DBException& e) {
if (ErrorCodes::isRetriableError(e)) {
static constexpr char errorMsg[] =
diff --git a/src/mongo/db/repl/isself.cpp b/src/mongo/db/repl/isself.cpp
index 1ce196edc69..cc35bcacf4b 100644
--- a/src/mongo/db/repl/isself.cpp
+++ b/src/mongo/db/repl/isself.cpp
@@ -293,7 +293,7 @@ bool isSelfSlowPath(const HostAndPort& hostAndPort,
}
}
BSONObj out;
- bool ok = conn.runCommand("admin", BSON("_isSelf" << 1), out);
+ bool ok = conn.runCommand(DatabaseName(boost::none, "admin"), BSON("_isSelf" << 1), out);
bool me = ok && out["id"].type() == jstOID && instanceId == out["id"].OID();
return me;
diff --git a/src/mongo/db/repl/oplog_applier_impl_test.cpp b/src/mongo/db/repl/oplog_applier_impl_test.cpp
index 7252aabc100..e75c20b2707 100644
--- a/src/mongo/db/repl/oplog_applier_impl_test.cpp
+++ b/src/mongo/db/repl/oplog_applier_impl_test.cpp
@@ -3423,7 +3423,7 @@ public:
DBDirectClient client(_opCtx.get());
BSONObj result;
- ASSERT(client.runCommand(kNs.db().toString(), BSON("create" << kNs.coll()), result));
+ ASSERT(client.runCommand(kNs.dbName(), BSON("create" << kNs.coll()), result));
}
/**
@@ -3833,10 +3833,10 @@ TEST_F(OplogApplierImplTxnTableTest, MultiApplyUpdatesTheTransactionTable) {
DBDirectClient client(_opCtx.get());
BSONObj result;
- ASSERT(client.runCommand(ns0.db().toString(), BSON("create" << ns0.coll()), result));
- ASSERT(client.runCommand(ns1.db().toString(), BSON("create" << ns1.coll()), result));
- ASSERT(client.runCommand(ns2.db().toString(), BSON("create" << ns2.coll()), result));
- ASSERT(client.runCommand(ns3.db().toString(), BSON("create" << ns3.coll()), result));
+ ASSERT(client.runCommand(ns0.dbName(), BSON("create" << ns0.coll()), result));
+ ASSERT(client.runCommand(ns1.dbName(), BSON("create" << ns1.coll()), result));
+ ASSERT(client.runCommand(ns2.dbName(), BSON("create" << ns2.coll()), result));
+ ASSERT(client.runCommand(ns3.dbName(), BSON("create" << ns3.coll()), result));
auto uuid0 = [&] {
return AutoGetCollectionForRead(_opCtx.get(), ns0).getCollection()->uuid();
}();
diff --git a/src/mongo/db/repl/primary_only_service_test.cpp b/src/mongo/db/repl/primary_only_service_test.cpp
index f32dae2ffd4..2b019c61879 100644
--- a/src/mongo/db/repl/primary_only_service_test.cpp
+++ b/src/mongo/db/repl/primary_only_service_test.cpp
@@ -289,7 +289,7 @@ private:
auto opCtx = opCtxHolder.get();
DBDirectClient client(opCtx);
BSONObj result;
- client.runCommand(nss.db().toString(),
+ client.runCommand(nss.dbName(),
BSON("createIndexes"
<< nss.coll().toString() << "indexes"
<< BSON_ARRAY(BSON("key" << BSON("x" << 1) << "name"
diff --git a/src/mongo/db/repl/rollback_source_impl.cpp b/src/mongo/db/repl/rollback_source_impl.cpp
index 8b427be197c..315de2df6af 100644
--- a/src/mongo/db/repl/rollback_source_impl.cpp
+++ b/src/mongo/db/repl/rollback_source_impl.cpp
@@ -61,7 +61,8 @@ const HostAndPort& RollbackSourceImpl::getSource() const {
int RollbackSourceImpl::getRollbackId() const {
bo info;
- _getConnection()->runCommand("admin", BSON("replSetGetRBID" << 1), info);
+ _getConnection()->runCommand(
+ DatabaseName(boost::none, "admin"), BSON("replSetGetRBID" << 1), info);
return info["rbid"].numberInt();
}
diff --git a/src/mongo/db/repl/storage_timestamp_test.cpp b/src/mongo/db/repl/storage_timestamp_test.cpp
index 466fdf3de34..26bf7b1cdbe 100644
--- a/src/mongo/db/repl/storage_timestamp_test.cpp
+++ b/src/mongo/db/repl/storage_timestamp_test.cpp
@@ -2073,7 +2073,7 @@ TEST_F(StorageTimestampTest, TimestampMultiIndexBuilds) {
BSON("createIndexes" << nss.coll() << "indexes" << BSON_ARRAY(index1 << index2)
<< "commitQuorum" << 0);
BSONObj result;
- ASSERT(client.runCommand(nss.db().toString(), createIndexesCmdObj, result)) << result;
+ ASSERT(client.runCommand(nss.dbName(), createIndexesCmdObj, result)) << result;
}
auto indexCreateInitTs = queryOplog(BSON("op"
@@ -2172,7 +2172,7 @@ TEST_F(StorageTimestampTest, TimestampMultiIndexBuildsDuringRename) {
BSON("createIndexes" << nss.coll() << "indexes" << BSON_ARRAY(index1 << index2)
<< "commitQuorum" << 0);
BSONObj result;
- ASSERT(client.runCommand(nss.db().toString(), createIndexesCmdObj, result)) << result;
+ ASSERT(client.runCommand(nss.dbName(), createIndexesCmdObj, result)) << result;
}
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_X);
@@ -2187,7 +2187,7 @@ TEST_F(StorageTimestampTest, TimestampMultiIndexBuildsDuringRename) {
// Rename collection.
BSONObj renameResult;
ASSERT(client.runCommand(
- "admin",
+ DatabaseName(boost::none, "admin"),
BSON("renameCollection" << nss.ns() << "to" << renamedNss.ns() << "dropTarget" << true),
renameResult))
<< renameResult;
@@ -2298,7 +2298,7 @@ TEST_F(StorageTimestampTest, TimestampAbortIndexBuild) {
DBDirectClient client(_opCtx);
BSONObj result;
- ASSERT_FALSE(client.runCommand(nss.db().toString(), createIndexesCmdObj, result));
+ ASSERT_FALSE(client.runCommand(nss.dbName(), createIndexesCmdObj, result));
ASSERT_EQUALS(ErrorCodes::DuplicateKey, getStatusFromCommandResult(result));
}
@@ -3076,7 +3076,7 @@ TEST_F(StorageTimestampTest, MultipleTimestampsForMultikeyWrites) {
BSON("createIndexes" << nss.coll() << "indexes" << BSON_ARRAY(index1 << index2)
<< "commitQuorum" << 0);
BSONObj result;
- ASSERT(client.runCommand(nss.db().toString(), createIndexesCmdObj, result)) << result;
+ ASSERT(client.runCommand(nss.dbName(), createIndexesCmdObj, result)) << result;
}
AutoGetCollection autoColl(_opCtx, nss, LockMode::MODE_IX);
diff --git a/src/mongo/db/repl/tenant_all_database_cloner.cpp b/src/mongo/db/repl/tenant_all_database_cloner.cpp
index 70c55eb373a..ab56852ed99 100644
--- a/src/mongo/db/repl/tenant_all_database_cloner.cpp
+++ b/src/mongo/db/repl/tenant_all_database_cloner.cpp
@@ -99,7 +99,8 @@ BaseCloner::AfterStageBehavior TenantAllDatabaseCloner::listDatabasesStage() {
BSONObj readResult;
BSONObj cmd = ClonerUtils::buildMajorityWaitRequest(_operationTime);
- getClient()->runCommand("admin", cmd, readResult, QueryOption_SecondaryOk);
+ getClient()->runCommand(
+ DatabaseName(boost::none, "admin"), cmd, readResult, QueryOption_SecondaryOk);
uassertStatusOKWithContext(
getStatusFromCommandResult(readResult),
"TenantAllDatabaseCloner failed to get listDatabases result majority-committed");
@@ -162,7 +163,8 @@ BaseCloner::AfterStageBehavior TenantAllDatabaseCloner::listExistingDatabasesSta
clonedDatabases.emplace_back(dbName);
BSONObj res;
- client.runCommand(dbName, BSON("dbStats" << 1), res);
+ // TODO SERVER-72945: Use dbName which is DatabaseName object already.
+ client.runCommand(DatabaseName(boost::none, dbName), BSON("dbStats" << 1), res);
if (auto status = getStatusFromCommandResult(res); !status.isOK()) {
LOGV2_WARNING(5522900,
"Skipping recording of data size metrics for database due to failure "
@@ -232,7 +234,8 @@ BaseCloner::AfterStageBehavior TenantAllDatabaseCloner::initializeStatsStage() {
long long approxTotalDataSizeLeftOnRemote = 0;
for (const auto& dbName : _databases) {
BSONObj res;
- getClient()->runCommand(dbName, BSON("dbStats" << 1), res);
+ // TODO SERVER-72945: Use dbName which is DatabaseName object already.
+ getClient()->runCommand(DatabaseName(boost::none, dbName), BSON("dbStats" << 1), res);
if (auto status = getStatusFromCommandResult(res); !status.isOK()) {
LOGV2_WARNING(5426600,
"Skipping recording of data size metrics for database due to failure "
diff --git a/src/mongo/db/repl/tenant_collection_cloner.cpp b/src/mongo/db/repl/tenant_collection_cloner.cpp
index 834fb288f47..de558fc74fd 100644
--- a/src/mongo/db/repl/tenant_collection_cloner.cpp
+++ b/src/mongo/db/repl/tenant_collection_cloner.cpp
@@ -163,8 +163,7 @@ BaseCloner::AfterStageBehavior TenantCollectionCloner::countStage() {
}
BSONObj res;
- getClient()->runCommand(
- _sourceNss.db().toString(), BSON("collStats" << _sourceNss.coll()), res);
+ getClient()->runCommand(_sourceNss.dbName(), BSON("collStats" << _sourceNss.coll()), res);
auto status = getStatusFromCommandResult(res);
if (!status.isOK()) {
LOGV2_WARNING(5426601,
@@ -245,7 +244,8 @@ BaseCloner::AfterStageBehavior TenantCollectionCloner::listIndexesStage() {
BSONObj readResult;
BSONObj cmd = ClonerUtils::buildMajorityWaitRequest(_operationTime);
- getClient()->runCommand("admin", cmd, readResult, QueryOption_SecondaryOk);
+ getClient()->runCommand(
+ DatabaseName(boost::none, "admin"), cmd, readResult, QueryOption_SecondaryOk);
uassertStatusOKWithContext(
getStatusFromCommandResult(readResult),
"TenantCollectionCloner failed to get listIndexes result majority-committed");
diff --git a/src/mongo/db/repl/tenant_database_cloner.cpp b/src/mongo/db/repl/tenant_database_cloner.cpp
index 91462a8eae8..b326c1128e3 100644
--- a/src/mongo/db/repl/tenant_database_cloner.cpp
+++ b/src/mongo/db/repl/tenant_database_cloner.cpp
@@ -115,7 +115,8 @@ BaseCloner::AfterStageBehavior TenantDatabaseCloner::listCollectionsStage() {
BSONObj readResult;
BSONObj cmd = ClonerUtils::buildMajorityWaitRequest(_operationTime);
- getClient()->runCommand("admin", cmd, readResult, QueryOption_SecondaryOk);
+ getClient()->runCommand(
+ DatabaseName(boost::none, "admin"), cmd, readResult, QueryOption_SecondaryOk);
uassertStatusOKWithContext(
getStatusFromCommandResult(readResult),
"TenantDatabaseCloner failed to get listCollections result majority-committed");
@@ -224,7 +225,9 @@ BaseCloner::AfterStageBehavior TenantDatabaseCloner::listExistingCollectionsStag
clonedCollectionUUIDs.emplace_back(result.getInfo().getUuid());
BSONObj res;
- client.runCommand(_dbName, BSON("collStats" << result.getName()), res);
+ // TODO SERVER-72945: Use the _dbName which is DatabaseName object already.
+ client.runCommand(
+ DatabaseName(boost::none, _dbName), BSON("collStats" << result.getName()), res);
if (auto status = getStatusFromCommandResult(res); !status.isOK()) {
LOGV2_WARNING(5522901,
"Skipping recording of data size metrics for database due to failure "
diff --git a/src/mongo/db/repl/tenant_migration_donor_service.cpp b/src/mongo/db/repl/tenant_migration_donor_service.cpp
index 51c305c646e..df716176ecf 100644
--- a/src/mongo/db/repl/tenant_migration_donor_service.cpp
+++ b/src/mongo/db/repl/tenant_migration_donor_service.cpp
@@ -263,7 +263,7 @@ ExecutorFuture<void> TenantMigrationDonorService::createStateDocumentTTLIndex(
BSONObj result;
client.runCommand(
- nss.db().toString(),
+ nss.dbName(),
BSON("createIndexes"
<< nss.coll().toString() << "indexes"
<< BSON_ARRAY(BSON("key" << BSON("expireAt" << 1) << "name" << kTTLIndexName
@@ -290,7 +290,7 @@ ExecutorFuture<void> TenantMigrationDonorService::createExternalKeysTTLIndex(
BSONObj result;
client.runCommand(
- nss.db().toString(),
+ nss.dbName(),
BSON("createIndexes"
<< nss.coll().toString() << "indexes"
<< BSON_ARRAY(BSON("key" << BSON("ttlExpiresAt" << 1) << "name"
diff --git a/src/mongo/db/repl/tenant_migration_recipient_service.cpp b/src/mongo/db/repl/tenant_migration_recipient_service.cpp
index cf87a25bc51..30a92773e96 100644
--- a/src/mongo/db/repl/tenant_migration_recipient_service.cpp
+++ b/src/mongo/db/repl/tenant_migration_recipient_service.cpp
@@ -320,7 +320,7 @@ ExecutorFuture<void> TenantMigrationRecipientService::_rebuildService(
BSONObj result;
client.runCommand(
- nss.db().toString(),
+ nss.dbName(),
BSON("createIndexes"
<< nss.coll().toString() << "indexes"
<< BSON_ARRAY(BSON("key" << BSON("expireAt" << 1) << "name" << kTTLIndexName
@@ -1762,7 +1762,8 @@ TenantMigrationRecipientService::Instance::_fetchRetryableWritesOplogBeforeStart
BSONObj readResult;
BSONObj cmd = ClonerUtils::buildMajorityWaitRequest(*operationTime);
- _client.get()->runCommand("admin", cmd, readResult, QueryOption_SecondaryOk);
+ _client.get()->runCommand(
+ DatabaseName(boost::none, "admin"), cmd, readResult, QueryOption_SecondaryOk);
uassertStatusOKWithContext(
getStatusFromCommandResult(readResult),
"Failed to wait for retryable writes pre-fetch result majority committed");
diff --git a/src/mongo/db/s/add_shard_cmd.cpp b/src/mongo/db/s/add_shard_cmd.cpp
index e839049e525..82b4077f619 100644
--- a/src/mongo/db/s/add_shard_cmd.cpp
+++ b/src/mongo/db/s/add_shard_cmd.cpp
@@ -77,7 +77,8 @@ public:
DBDirectClient localClient(opCtx);
BSONObj res;
- localClient.runCommand(NamespaceString::kAdminDb.toString(), shardIdUpsertCmd, res);
+ localClient.runCommand(
+ DatabaseName(boost::none, NamespaceString::kAdminDb), shardIdUpsertCmd, res);
uassertStatusOK(getStatusFromCommandResult(res));
diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp
index ae1d331d192..cf04ddd7b24 100644
--- a/src/mongo/db/s/config/sharding_catalog_manager.cpp
+++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp
@@ -114,7 +114,7 @@ BSONObj executeConfigRequest(OperationContext* opCtx,
invariant(nss.db() == NamespaceString::kConfigDb);
DBDirectClient client(opCtx);
BSONObj result;
- client.runCommand(nss.db().toString(), request.toBSON(), result);
+ client.runCommand(nss.dbName(), request.toBSON(), result);
return result;
}
@@ -489,7 +489,7 @@ Status ShardingCatalogManager::_initConfigCollections(OperationContext* opCtx) {
BSONObj cmd = BSON("create" << CollectionType::ConfigNS.coll());
BSONObj result;
- const bool ok = client.runCommand(CollectionType::ConfigNS.db().toString(), cmd, result);
+ const bool ok = client.runCommand(CollectionType::ConfigNS.dbName(), cmd, result);
if (!ok) { // create returns error NamespaceExists if collection already exists
Status status = getStatusFromCommandResult(result);
if (status != ErrorCodes::NamespaceExists) {
@@ -536,7 +536,7 @@ Status ShardingCatalogManager::_initConfigSettings(OperationContext* opCtx) {
BSONObj cmd = BSON("create" << NamespaceString::kConfigSettingsNamespace.coll());
BSONObj result;
const bool ok =
- client.runCommand(NamespaceString::kConfigSettingsNamespace.db().toString(), cmd, result);
+ client.runCommand(NamespaceString::kConfigSettingsNamespace.dbName(), cmd, result);
if (!ok) { // create returns error NamespaceExists if collection already exists
Status status = getStatusFromCommandResult(result);
if (status != ErrorCodes::NamespaceExists) {
diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp
index 131a7035262..ddd383991b0 100644
--- a/src/mongo/db/s/create_collection_coordinator.cpp
+++ b/src/mongo/db/s/create_collection_coordinator.cpp
@@ -1094,7 +1094,7 @@ void CreateCollectionCoordinator::_createCollectionAndIndexes(
BSONObj createRes;
DBDirectClient localClient(opCtx);
- localClient.runCommand(nss().db().toString(), createCmd, createRes);
+ localClient.runCommand(nss().dbName(), createCmd, createRes);
auto createStatus = getStatusFromCommandResult(createRes);
if (!createStatus.isOK() && createStatus.code() == ErrorCodes::NamespaceExists) {
diff --git a/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp b/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp
index 01cf6a8ac6c..0e21d2a6b7e 100644
--- a/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp
+++ b/src/mongo/db/s/global_index/global_index_cloning_service_test.cpp
@@ -309,7 +309,8 @@ public:
CreateGlobalIndex createGlobalIndex(_indexCollectionUUID);
createGlobalIndex.setDbName({boost::none, "admin"});
BSONObj cmdResult;
- auto success = client.runCommand("admin", createGlobalIndex.toBSON({}), cmdResult);
+ auto success =
+ client.runCommand({boost::none, "admin"}, createGlobalIndex.toBSON({}), cmdResult);
ASSERT(success) << "createGlobalIndex cmd failed with result: " << cmdResult;
}
diff --git a/src/mongo/db/s/global_index/global_index_inserter_test.cpp b/src/mongo/db/s/global_index/global_index_inserter_test.cpp
index 2ffc1eae4a3..760886964f9 100644
--- a/src/mongo/db/s/global_index/global_index_inserter_test.cpp
+++ b/src/mongo/db/s/global_index/global_index_inserter_test.cpp
@@ -78,7 +78,8 @@ public:
CreateGlobalIndex createGlobalIndex(_indexUUID);
createGlobalIndex.setDbName({boost::none, "admin"});
BSONObj cmdResult;
- auto success = client.runCommand("admin", createGlobalIndex.toBSON({}), cmdResult);
+ auto success =
+ client.runCommand({boost::none, "admin"}, createGlobalIndex.toBSON({}), cmdResult);
ASSERT(success) << "createGlobalIndex cmd failed with result: " << cmdResult;
}
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 8a7851ba3c8..54a7b3abbff 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -972,7 +972,7 @@ void MigrationDestinationManager::_dropLocalIndexesIfNecessary(
recipientIndex[IndexDescriptor::kKeyPatternFieldName].Obj())) {
BSONObj info;
if (!client.runCommand(
- nss.db().toString(),
+ nss.dbName(),
BSON("dropIndexes" << nss.coll() << "index" << indexNameElem),
info))
uassertStatusOK(getStatusFromCommandResult(info));
diff --git a/src/mongo/db/s/move_primary_coordinator.cpp b/src/mongo/db/s/move_primary_coordinator.cpp
index 84e29628587..3f95ebc25cd 100644
--- a/src/mongo/db/s/move_primary_coordinator.cpp
+++ b/src/mongo/db/s/move_primary_coordinator.cpp
@@ -463,7 +463,7 @@ void MovePrimaryCoordinator::dropStaleDataOnDonor(OperationContext* opCtx) const
for (const auto& nss : *_doc.getCollectionsToClone()) {
const auto dropStatus = [&] {
BSONObj dropResult;
- dbClient.runCommand(_dbName.toString(), BSON("drop" << nss.coll()), dropResult);
+ dbClient.runCommand(_dbName, BSON("drop" << nss.coll()), dropResult);
return getStatusFromCommandResult(dropResult);
}();
diff --git a/src/mongo/db/s/move_primary_source_manager.cpp b/src/mongo/db/s/move_primary_source_manager.cpp
index 0df7fc1fad9..add1bd585eb 100644
--- a/src/mongo/db/s/move_primary_source_manager.cpp
+++ b/src/mongo/db/s/move_primary_source_manager.cpp
@@ -465,7 +465,7 @@ Status MovePrimarySourceManager::cleanStaleData(OperationContext* opCtx) {
DBDirectClient client(opCtx);
for (auto& coll : _clonedColls) {
BSONObj dropCollResult;
- client.runCommand(_dbname.toString(), BSON("drop" << coll.coll()), dropCollResult);
+ client.runCommand(_dbname, BSON("drop" << coll.coll()), dropCollResult);
Status dropStatus = getStatusFromCommandResult(dropCollResult);
if (!dropStatus.isOK()) {
LOGV2(22045,
diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
index 021699d4adc..52d006f5308 100644
--- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
+++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp
@@ -740,7 +740,7 @@ void updateTagsDocsForTempNss(OperationContext* opCtx,
// currently have 'ns' as the temporary collection namespace.
DBDirectClient client(opCtx);
BSONObj tagsRes;
- client.runCommand(tagsRequest.getNS().db().toString(), tagsRequest.toBSON(), tagsRes);
+ client.runCommand(tagsRequest.getNS().dbName(), tagsRequest.toBSON(), tagsRes);
uassertStatusOK(getStatusFromWriteCommandReply(tagsRes));
}
@@ -1071,7 +1071,7 @@ ExecutorFuture<void> ReshardingCoordinatorService::_rebuildService(
DBDirectClient client(opCtx);
BSONObj result;
client.runCommand(
- nss.db().toString(),
+ nss.dbName(),
BSON("createIndexes"
<< nss.coll().toString() << "indexes"
<< BSON_ARRAY(BSON("key" << BSON("active" << 1) << "name"
diff --git a/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp b/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp
index d620bee286d..62b408da0b7 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_fetcher_test.cpp
@@ -248,7 +248,7 @@ public:
onCommand([&](const executor::RemoteCommandRequest& request) -> StatusWith<BSONObj> {
DBDirectClient client(cc().getOperationContext());
BSONObj result;
- bool res = client.runCommand(request.dbname, request.cmdObj, result);
+ bool res = client.runCommand({boost::none, request.dbname}, request.cmdObj, result);
if (res == false || result.hasField("cursorsKilled") ||
result["cursor"]["id"].Long() == 0) {
hasMore = false;
diff --git a/src/mongo/db/s/shard_key_util.cpp b/src/mongo/db/s/shard_key_util.cpp
index 8bc0929970a..7c585ff9677 100644
--- a/src/mongo/db/s/shard_key_util.cpp
+++ b/src/mongo/db/s/shard_key_util.cpp
@@ -289,7 +289,7 @@ void ValidationBehaviorsShardCollection::verifyUsefulNonMultiKeyIndex(
const NamespaceString& nss, const BSONObj& proposedKey) const {
BSONObj res;
auto success = _localClient->runCommand(
- "admin",
+ DatabaseName(boost::none, "admin"),
BSON(kCheckShardingIndexCmdName << nss.ns() << kKeyPatternField << proposedKey),
res);
uassert(ErrorCodes::InvalidOptions, res["errmsg"].str(), success);
@@ -313,7 +313,7 @@ void ValidationBehaviorsShardCollection::createShardKeyIndex(
defaultCollation && !defaultCollation->isEmpty() ? CollationSpec::kSimpleSpec : BSONObj();
auto createIndexesCmd = makeCreateIndexesCmd(nss, proposedKey, collation, unique);
BSONObj res;
- _localClient->runCommand(nss.db().toString(), createIndexesCmd, res);
+ _localClient->runCommand(nss.dbName(), createIndexesCmd, res);
uassertStatusOK(getStatusFromCommandResult(res));
}
diff --git a/src/mongo/db/serverless/shard_split_donor_service.cpp b/src/mongo/db/serverless/shard_split_donor_service.cpp
index ed52e344a70..afa630bc9d8 100644
--- a/src/mongo/db/serverless/shard_split_donor_service.cpp
+++ b/src/mongo/db/serverless/shard_split_donor_service.cpp
@@ -728,7 +728,7 @@ ExecutorFuture<void> ShardSplitDonorService::DonorStateMachine::_applySplitConfi
DBDirectClient client(opCtxHolder.get());
BSONObj result;
const bool returnValue =
- client.runCommand(NamespaceString::kAdminDb.toString(),
+ client.runCommand(DatabaseName(boost::none, NamespaceString::kAdminDb),
BSON("replSetReconfig" << splitConfig.toBSON()),
result);
uassert(ErrorCodes::BadValue,
@@ -1219,7 +1219,7 @@ ExecutorFuture<void> ShardSplitDonorService::DonorStateMachine::_removeSplitConf
BSONObj result;
const bool returnValue =
- client.runCommand(NamespaceString::kAdminDb.toString(),
+ client.runCommand(DatabaseName(boost::none, NamespaceString::kAdminDb),
BSON("replSetReconfig" << newConfigBob.obj()),
result);
uassert(
diff --git a/src/mongo/db/session/sessions_collection.cpp b/src/mongo/db/session/sessions_collection.cpp
index 4fc79189206..78492298140 100644
--- a/src/mongo/db/session/sessions_collection.cpp
+++ b/src/mongo/db/session/sessions_collection.cpp
@@ -156,7 +156,7 @@ SessionsCollection::SendBatchFn SessionsCollection::makeSendFnForBatchWrite(
const NamespaceString& ns, DBClientBase* client) {
auto send = [client, ns](BSONObj batch) {
BSONObj res;
- if (!client->runCommand(ns.db().toString(), batch, res)) {
+ if (!client->runCommand(ns.dbName(), batch, res)) {
uassertStatusOK(getStatusFromCommandResult(res));
}
};
@@ -168,7 +168,7 @@ SessionsCollection::SendBatchFn SessionsCollection::makeSendFnForCommand(const N
DBClientBase* client) {
auto send = [client, ns](BSONObj cmd) {
BSONObj res;
- if (!client->runCommand(ns.db().toString(), cmd, res)) {
+ if (!client->runCommand(ns.dbName(), cmd, res)) {
uassertStatusOK(getStatusFromCommandResult(res));
}
};
@@ -180,7 +180,7 @@ SessionsCollection::FindBatchFn SessionsCollection::makeFindFnForCommand(const N
DBClientBase* client) {
auto send = [client, ns](BSONObj cmd) -> BSONObj {
BSONObj res;
- if (!client->runCommand(ns.db().toString(), cmd, res)) {
+ if (!client->runCommand(ns.dbName(), cmd, res)) {
uassertStatusOK(getStatusFromCommandResult(res));
}
diff --git a/src/mongo/db/session/sessions_collection_rs.cpp b/src/mongo/db/session/sessions_collection_rs.cpp
index 865f0b825e9..5483466eaa7 100644
--- a/src/mongo/db/session/sessions_collection_rs.cpp
+++ b/src/mongo/db/session/sessions_collection_rs.cpp
@@ -117,32 +117,31 @@ auto SessionsCollectionRS::_dispatch(const NamespaceString& ns,
}
void SessionsCollectionRS::setupSessionsCollection(OperationContext* opCtx) {
- _dispatch(
- NamespaceString::kLogicalSessionsNamespace,
- opCtx,
- [&] {
- try {
- checkSessionsCollectionExists(opCtx);
- } catch (const DBException& ex) {
-
- DBDirectClient client(opCtx);
- BSONObj cmd;
-
- if (ex.code() == ErrorCodes::IndexOptionsConflict) {
- cmd = generateCollModCmd();
- } else {
- // Creating the TTL index will auto-generate the collection.
- cmd = generateCreateIndexesCmd();
- }
-
- BSONObj info;
- if (!client.runCommand(
- NamespaceString::kLogicalSessionsNamespace.db().toString(), cmd, info)) {
- uassertStatusOK(getStatusFromCommandResult(info));
- }
- }
- },
- [&](DBClientBase*) { checkSessionsCollectionExists(opCtx); });
+ _dispatch(NamespaceString::kLogicalSessionsNamespace,
+ opCtx,
+ [&] {
+ try {
+ checkSessionsCollectionExists(opCtx);
+ } catch (const DBException& ex) {
+
+ DBDirectClient client(opCtx);
+ BSONObj cmd;
+
+ if (ex.code() == ErrorCodes::IndexOptionsConflict) {
+ cmd = generateCollModCmd();
+ } else {
+ // Creating the TTL index will auto-generate the collection.
+ cmd = generateCreateIndexesCmd();
+ }
+
+ BSONObj info;
+ if (!client.runCommand(
+ NamespaceString::kLogicalSessionsNamespace.dbName(), cmd, info)) {
+ uassertStatusOK(getStatusFromCommandResult(info));
+ }
+ }
+ },
+ [&](DBClientBase*) { checkSessionsCollectionExists(opCtx); });
}
void SessionsCollectionRS::checkSessionsCollectionExists(OperationContext* opCtx) {
diff --git a/src/mongo/db/session/sessions_collection_standalone.cpp b/src/mongo/db/session/sessions_collection_standalone.cpp
index 94fb61cfc75..ef63bd4b2e0 100644
--- a/src/mongo/db/session/sessions_collection_standalone.cpp
+++ b/src/mongo/db/session/sessions_collection_standalone.cpp
@@ -59,8 +59,7 @@ void SessionsCollectionStandalone::setupSessionsCollection(OperationContext* opC
}
BSONObj info;
- if (!client.runCommand(
- NamespaceString::kLogicalSessionsNamespace.db().toString(), cmd, info)) {
+ if (!client.runCommand(NamespaceString::kLogicalSessionsNamespace.dbName(), cmd, info)) {
uassertStatusOKWithContext(getStatusFromCommandResult(info),
str::stream() << "Failed to create "
<< NamespaceString::kLogicalSessionsNamespace);
diff --git a/src/mongo/db/transaction/transaction_api.cpp b/src/mongo/db/transaction/transaction_api.cpp
index 313b3825991..484c522c7f2 100644
--- a/src/mongo/db/transaction/transaction_api.cpp
+++ b/src/mongo/db/transaction/transaction_api.cpp
@@ -569,7 +569,7 @@ SemiFuture<BSONObj> Transaction::_commitOrAbort(StringData dbName, StringData cm
}
return ExecutorFuture<void>(_executor)
- .then([this, dbNameCopy = dbName.toString(), cmdObj = cmdBuilder.obj()] {
+ .then([this, dbNameCopy = dbName, cmdObj = cmdBuilder.obj()] {
return _txnClient->runCommand(dbNameCopy, cmdObj);
})
// Safe to inline because the continuation only holds state.
diff --git a/src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp b/src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp
index b91e93dd336..3a5a784b4a9 100644
--- a/src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp
+++ b/src/mongo/db/transaction/transaction_participant_retryable_writes_test.cpp
@@ -498,7 +498,7 @@ TEST_F(TransactionParticipantRetryableWritesTest, SessionTransactionsCollectionN
BSONObj dropResult;
DBDirectClient client(opCtx());
const auto& nss = NamespaceString::kSessionTransactionsTableNamespace;
- ASSERT(client.runCommand(nss.db().toString(), BSON("drop" << nss.coll()), dropResult));
+ ASSERT(client.runCommand(nss.dbName(), BSON("drop" << nss.coll()), dropResult));
const TxnNumber txnNum = 21;
txnParticipant.beginOrContinue(