Skip to content

Commit 892a8ba

Browse files
committed
address review
1 parent 4d776e0 commit 892a8ba

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

packages/mongodb-runner/src/mongocluster.ts

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -534,27 +534,7 @@ export class MongoCluster extends EventEmitter<MongoClusterEvents> {
534534
}
535535

536536
await cluster.addAuthIfNeeded();
537-
538-
// Set up requireApiVersion if requested.
539-
if (options.requireApiVersion !== undefined) {
540-
if (options.topology === 'replset') {
541-
throw new Error(
542-
'requireApiVersion is not supported for replica sets, see SERVER-97010',
543-
);
544-
}
545-
await Promise.all(
546-
[...cluster.servers].map(
547-
async (child) =>
548-
await child.withClient(async (client) => {
549-
const admin = client.db('admin');
550-
await admin.command({ setParameter: 1, requireApiVersion: true });
551-
}),
552-
),
553-
);
554-
await cluster.updateDefaultConnectionOptions({
555-
serverApi: String(options.requireApiVersion) as '1',
556-
});
557-
}
537+
await cluster.addRequireApiVersionIfNeeded(options);
558538
return cluster;
559539
}
560540

@@ -563,6 +543,32 @@ export class MongoCluster extends EventEmitter<MongoClusterEvents> {
563543
yield* this.shards;
564544
}
565545

546+
async addRequireApiVersionIfNeeded({
547+
...options
548+
}: MongoClusterOptions): Promise<void> {
549+
// Set up requireApiVersion if requested.
550+
if (options.requireApiVersion !== undefined) {
551+
return;
552+
}
553+
if (options.topology === 'replset') {
554+
throw new Error(
555+
'requireApiVersion is not supported for replica sets, see SERVER-97010',
556+
);
557+
}
558+
await Promise.all(
559+
[...this.servers].map(
560+
async (child) =>
561+
await child.withClient(async (client) => {
562+
const admin = client.db('admin');
563+
await admin.command({ setParameter: 1, requireApiVersion: true });
564+
}),
565+
),
566+
);
567+
await this.updateDefaultConnectionOptions({
568+
serverApi: String(options.requireApiVersion) as '1',
569+
});
570+
}
571+
566572
async addAuthIfNeeded(): Promise<void> {
567573
if (!this.users?.length) return;
568574
// Sleep to give time for a possible replset election to settle.

packages/mongodb-runner/src/mongoserver.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ export class MongoServer extends EventEmitter<MongoServerEvents> {
287287
logEntryStream.resume();
288288

289289
srv.port = port;
290+
// If a keyFile is present, we cannot read or write on the server until
291+
// a user is added to the primary.
290292
if (!options.args?.includes('--keyFile')) {
291293
const buildInfoError = await srv._populateBuildInfo('insert-new');
292294
if (buildInfoError) {
@@ -340,8 +342,8 @@ export class MongoServer extends EventEmitter<MongoServerEvents> {
340342
if (status.authInfo.authenticatedUsers.length > 0) {
341343
return true;
342344
}
343-
// If the server does not support auth, just get the build info without
344-
// setting the metadata.
345+
// The server is most likely an arbiter, which does not support
346+
// authenticated users but does support getting the buildInfo.
345347
debug('Server does not support authorization', this.port);
346348
this.buildInfo = await client.db('admin').command({ buildInfo: 1 });
347349
return false;

0 commit comments

Comments
 (0)