@@ -39,6 +39,8 @@ export interface MongoServerOptions {
3939 args ?: string [ ] ;
4040 /** Docker image or options to run the MongoDB binary in a container. */
4141 docker ?: string | string [ ] ;
42+ /** The host address of the servers (default: '127.0.0.1') */
43+ host ?: string ;
4244 /** Internal options for the MongoDB client used by this server instance. */
4345 internalClientOptions ?: Partial < MongoClientOptions > ;
4446 /** Internal option -- if this is an arbiter, it does not understand user auth */
@@ -55,6 +57,7 @@ interface SerializedServerProperties {
5557 _id : string ;
5658 pid ?: number ;
5759 port ?: number ;
60+ host ?: string ;
5861 dbPath ?: string ;
5962 defaultConnectionOptions ?: Partial < MongoClientOptions > ;
6063 startTime : string ;
@@ -84,6 +87,7 @@ export class MongoServer extends EventEmitter<MongoServerEvents> {
8487 private buildInfo ?: Document ;
8588 private childProcess ?: ChildProcess ;
8689 private pid ?: number ;
90+ private host = '127.0.0.1' ;
8791 private port ?: number ;
8892 private dbPath ?: string ;
8993 private closing = false ;
@@ -109,6 +113,7 @@ export class MongoServer extends EventEmitter<MongoServerEvents> {
109113 _id : this . uuid ,
110114 pid : this . pid ,
111115 port : this . port ,
116+ host : this . host ,
112117 dbPath : this . dbPath ,
113118 startTime : this . startTime ,
114119 hasInsertedMetadataCollEntry : this . hasInsertedMetadataCollEntry ,
@@ -126,6 +131,9 @@ export class MongoServer extends EventEmitter<MongoServerEvents> {
126131 const srv = new MongoServer ( ) ;
127132 srv . uuid = serialized . _id ;
128133 srv . port = serialized . port ;
134+ if ( serialized . host ) {
135+ srv . host = serialized . host ;
136+ }
129137 srv . defaultConnectionOptions = serialized . defaultConnectionOptions ;
130138 srv . closing = ! ! ( await srv . _populateBuildInfo ( 'restore-check' ) ) ;
131139 srv . isArbiter = ! ! serialized . isArbiter ;
@@ -144,7 +152,7 @@ export class MongoServer extends EventEmitter<MongoServerEvents> {
144152 if ( this . port === undefined ) {
145153 throw new Error ( 'Cannot get host/port for closed server' ) ;
146154 }
147- return `127.0.0.1 :${ this . port } ` ;
155+ return `${ this . host } :${ this . port } ` ;
148156 }
149157
150158 // Returns the version reported in the server log output
@@ -204,6 +212,9 @@ export class MongoServer extends EventEmitter<MongoServerEvents> {
204212 srv . isArbiter = ! ! options . isArbiter ;
205213 srv . isMongos = options . binary === 'mongos' ;
206214 srv . isConfigSvr = ! ! options . args ?. includes ( '--configsvr' ) ;
215+ if ( options . host ) {
216+ srv . host = options . host ;
217+ }
207218 const keyFilePath = getKeyFileOption ( options . args ) ;
208219 if ( keyFilePath ) {
209220 srv . keyFileContents = await fs . readFile ( keyFilePath , 'utf8' ) ;
0 commit comments