SERVER-117853 Add fallback if shard.primary does not exist (#47010)

GitOrigin-RevId: 53ee763b212889a23a9845996742aa6388cd6db3
This commit is contained in:
Erin Liang
2026-01-27 11:00:59 -05:00
committed by MongoDB Bot
parent f9e1714897
commit 078cca8e82

View File

@@ -92,8 +92,15 @@ if (topology.type === Topology.kShardedCluster) {
const shard = topology.shards[shardName];
if (shard.type === Topology.kReplicaSet) {
// Use primary if available, otherwise fall back to the first node.
let rst;
if (shard.primary) {
rst = new ReplSetTest(shard.primary);
} else {
assert(shard.nodes[0], "Shard has no primary and no nodes");
rst = new ReplSetTest(shard.nodes[0]);
}
// Await replication to ensure all of the shards are queryable.
const rst = new ReplSetTest(shard.primary);
rst.awaitReplication();
rst.nodes.forEach((node) => {
takeAction(node, operation);