From 9cd5195fa5693182231716f79114e184c01e5f1c Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 10 Feb 2026 09:08:36 -0600 Subject: [PATCH 1/7] feat(mongodb-runner): allow the server host to be specified --- packages/mongodb-runner/src/mongocluster.spec.ts | 8 ++++++++ packages/mongodb-runner/src/mongocluster.ts | 2 +- packages/mongodb-runner/src/mongoserver.ts | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/packages/mongodb-runner/src/mongocluster.spec.ts b/packages/mongodb-runner/src/mongocluster.spec.ts index d6dc855b..a4296480 100644 --- a/packages/mongodb-runner/src/mongocluster.spec.ts +++ b/packages/mongodb-runner/src/mongocluster.spec.ts @@ -179,6 +179,14 @@ describe('MongoCluster', function () { ).to.equal(1); }); + it('can use localhost as the host', async function () { + cluster = await MongoCluster.start({ + host: 'localhost', + topology: 'standalone', + tmpDir, + }); + }); + context('TLS', function () { it('can spawn a 8.x standalone mongod with TLS enabled and get build info (automatically added client key)', async function () { cluster = await MongoCluster.start({ diff --git a/packages/mongodb-runner/src/mongocluster.ts b/packages/mongodb-runner/src/mongocluster.ts index 533ec26b..da5a0ea9 100644 --- a/packages/mongodb-runner/src/mongocluster.ts +++ b/packages/mongodb-runner/src/mongocluster.ts @@ -143,7 +143,7 @@ export type ShardedOptions = { export type MongoClusterOptions = Pick< MongoServerOptions, - 'logDir' | 'tmpDir' | 'args' | 'binDir' | 'docker' | 'internalClientOptions' + 'logDir' | 'tmpDir' | 'args' | 'binDir' | 'docker' | 'internalClientOptions' | 'host' > & CommonOptions & RSOptions & diff --git a/packages/mongodb-runner/src/mongoserver.ts b/packages/mongodb-runner/src/mongoserver.ts index a19da349..417cc7f7 100644 --- a/packages/mongodb-runner/src/mongoserver.ts +++ b/packages/mongodb-runner/src/mongoserver.ts @@ -39,6 +39,8 @@ export interface MongoServerOptions { args?: string[]; /** Docker image or options to run the MongoDB binary in a container. */ docker?: string | string[]; + /** The host address of the servers (default: '127.0.0.1') */ + host?: string; /** Internal options for the MongoDB client used by this server instance. */ internalClientOptions?: Partial; /** Internal option -- if this is an arbiter, it does not understand user auth */ @@ -55,6 +57,7 @@ interface SerializedServerProperties { _id: string; pid?: number; port?: number; + host?: string; dbPath?: string; defaultConnectionOptions?: Partial; startTime: string; @@ -84,6 +87,7 @@ export class MongoServer extends EventEmitter { private buildInfo?: Document; private childProcess?: ChildProcess; private pid?: number; + private host?: string; private port?: number; private dbPath?: string; private closing = false; @@ -109,6 +113,7 @@ export class MongoServer extends EventEmitter { _id: this.uuid, pid: this.pid, port: this.port, + host: this.host, dbPath: this.dbPath, startTime: this.startTime, hasInsertedMetadataCollEntry: this.hasInsertedMetadataCollEntry, @@ -126,6 +131,7 @@ export class MongoServer extends EventEmitter { const srv = new MongoServer(); srv.uuid = serialized._id; srv.port = serialized.port; + srv.host = serialized.host; srv.defaultConnectionOptions = serialized.defaultConnectionOptions; srv.closing = !!(await srv._populateBuildInfo('restore-check')); srv.isArbiter = !!serialized.isArbiter; @@ -144,7 +150,7 @@ export class MongoServer extends EventEmitter { if (this.port === undefined) { throw new Error('Cannot get host/port for closed server'); } - return `127.0.0.1:${this.port}`; + return `${this.host}:${this.port}`; } // Returns the version reported in the server log output @@ -204,6 +210,7 @@ export class MongoServer extends EventEmitter { srv.isArbiter = !!options.isArbiter; srv.isMongos = options.binary === 'mongos'; srv.isConfigSvr = !!options.args?.includes('--configsvr'); + srv.host = options.host || '127.0.0.1'; const keyFilePath = getKeyFileOption(options.args); if (keyFilePath) { srv.keyFileContents = await fs.readFile(keyFilePath, 'utf8'); From 09733ad647906f636516896821332aa418baafa7 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 10 Feb 2026 09:11:14 -0600 Subject: [PATCH 2/7] update test --- packages/mongodb-runner/src/mongocluster.spec.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/mongodb-runner/src/mongocluster.spec.ts b/packages/mongodb-runner/src/mongocluster.spec.ts index a4296480..17ef3808 100644 --- a/packages/mongodb-runner/src/mongocluster.spec.ts +++ b/packages/mongodb-runner/src/mongocluster.spec.ts @@ -185,6 +185,8 @@ describe('MongoCluster', function () { topology: 'standalone', tmpDir, }); + expect(cluster.connectionString).to.be.a('string'); + expect(cluster.connectionString).to.include('localhost'); }); context('TLS', function () { From 0f6c39684ffe1760c18ad9eecbe8a07e47885c3a Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 10 Feb 2026 09:23:27 -0600 Subject: [PATCH 3/7] fix handling of host property --- packages/mongodb-runner/src/mongocluster.spec.ts | 1 + packages/mongodb-runner/src/mongoserver.ts | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/mongodb-runner/src/mongocluster.spec.ts b/packages/mongodb-runner/src/mongocluster.spec.ts index 17ef3808..b23ddd52 100644 --- a/packages/mongodb-runner/src/mongocluster.spec.ts +++ b/packages/mongodb-runner/src/mongocluster.spec.ts @@ -416,6 +416,7 @@ describe('MongoCluster', function () { return await client.db('config').collection('mongodbrunner').findOne(); }); expect(doc?._id).to.be.a('string'); + expect(doc?.host).to.equal('127.0.0.1'); await cluster.close(); }); diff --git a/packages/mongodb-runner/src/mongoserver.ts b/packages/mongodb-runner/src/mongoserver.ts index 417cc7f7..9d6efe5b 100644 --- a/packages/mongodb-runner/src/mongoserver.ts +++ b/packages/mongodb-runner/src/mongoserver.ts @@ -87,7 +87,7 @@ export class MongoServer extends EventEmitter { private buildInfo?: Document; private childProcess?: ChildProcess; private pid?: number; - private host?: string; + private host: string = '127.0.0.1'; private port?: number; private dbPath?: string; private closing = false; @@ -210,7 +210,9 @@ export class MongoServer extends EventEmitter { srv.isArbiter = !!options.isArbiter; srv.isMongos = options.binary === 'mongos'; srv.isConfigSvr = !!options.args?.includes('--configsvr'); - srv.host = options.host || '127.0.0.1'; + if (options.host) { + srv.host = options.host; + } const keyFilePath = getKeyFileOption(options.args); if (keyFilePath) { srv.keyFileContents = await fs.readFile(keyFilePath, 'utf8'); From 401a13d1da346ba6b371ba37b60b7cf28e94ed3e Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 10 Feb 2026 09:27:40 -0600 Subject: [PATCH 4/7] fix handling of host property --- packages/mongodb-runner/src/mongoserver.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/mongodb-runner/src/mongoserver.ts b/packages/mongodb-runner/src/mongoserver.ts index 9d6efe5b..7218c20b 100644 --- a/packages/mongodb-runner/src/mongoserver.ts +++ b/packages/mongodb-runner/src/mongoserver.ts @@ -131,7 +131,9 @@ export class MongoServer extends EventEmitter { const srv = new MongoServer(); srv.uuid = serialized._id; srv.port = serialized.port; - srv.host = serialized.host; + if (serialized.host) { + srv.host = serialized.host; + } srv.defaultConnectionOptions = serialized.defaultConnectionOptions; srv.closing = !!(await srv._populateBuildInfo('restore-check')); srv.isArbiter = !!serialized.isArbiter; From d5929ed5af92adb9c94186b9485a198f939c693e Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 10 Feb 2026 09:33:35 -0600 Subject: [PATCH 5/7] fix handling of host property --- packages/mongodb-runner/src/mongoserver.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mongodb-runner/src/mongoserver.ts b/packages/mongodb-runner/src/mongoserver.ts index 7218c20b..64d8bc75 100644 --- a/packages/mongodb-runner/src/mongoserver.ts +++ b/packages/mongodb-runner/src/mongoserver.ts @@ -87,7 +87,7 @@ export class MongoServer extends EventEmitter { private buildInfo?: Document; private childProcess?: ChildProcess; private pid?: number; - private host: string = '127.0.0.1'; + private host = '127.0.0.1'; private port?: number; private dbPath?: string; private closing = false; From 81e84a24f46f2396d3b7af4f8b9c6eb7a04a1d82 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 10 Feb 2026 10:56:54 -0600 Subject: [PATCH 6/7] lint and update tests --- packages/mongodb-runner/src/mongocluster.spec.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/mongodb-runner/src/mongocluster.spec.ts b/packages/mongodb-runner/src/mongocluster.spec.ts index b23ddd52..c82ef9c3 100644 --- a/packages/mongodb-runner/src/mongocluster.spec.ts +++ b/packages/mongodb-runner/src/mongocluster.spec.ts @@ -88,6 +88,7 @@ describe('MongoCluster', function () { tmpDir, }); expect(cluster.connectionString).to.be.a('string'); + expect(cluster.connectionString).to.include('127.0.0.1'); expect(cluster.serverVersion).to.match(/^6\./); expect(cluster.serverVariant).to.equal('community'); const { ok } = await cluster.withClient(async (client) => { @@ -187,6 +188,8 @@ describe('MongoCluster', function () { }); expect(cluster.connectionString).to.be.a('string'); expect(cluster.connectionString).to.include('localhost'); + cluster = await MongoCluster.deserialize(cluster.serialize()); + expect(cluster.connectionString).to.include('localhost'); }); context('TLS', function () { @@ -416,7 +419,6 @@ describe('MongoCluster', function () { return await client.db('config').collection('mongodbrunner').findOne(); }); expect(doc?._id).to.be.a('string'); - expect(doc?.host).to.equal('127.0.0.1'); await cluster.close(); }); From 02a3d1a9801f64cabc2c985df2939c8dc490e095 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 10 Feb 2026 11:03:05 -0600 Subject: [PATCH 7/7] lint --- packages/mongodb-runner/src/mongocluster.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/mongodb-runner/src/mongocluster.ts b/packages/mongodb-runner/src/mongocluster.ts index da5a0ea9..d8d97388 100644 --- a/packages/mongodb-runner/src/mongocluster.ts +++ b/packages/mongodb-runner/src/mongocluster.ts @@ -143,7 +143,13 @@ export type ShardedOptions = { export type MongoClusterOptions = Pick< MongoServerOptions, - 'logDir' | 'tmpDir' | 'args' | 'binDir' | 'docker' | 'internalClientOptions' | 'host' + | 'logDir' + | 'tmpDir' + | 'args' + | 'binDir' + | 'docker' + | 'internalClientOptions' + | 'host' > & CommonOptions & RSOptions &