Skip to content

Commit bbf75b8

Browse files
committed
feat(MongoInstance): add a new option instance.ip for binding mongod instance to specified ip addresses (by default 127.0.0.1)
Related #73
1 parent 7bdc367 commit bbf75b8

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ All options are optional.
4747
const mongod = new MongodbMemoryServer({
4848
instance: {
4949
port?: ?number, // by default choose any free port
50+
ip?: string, // by default '127.0.0.1', for binding to all IP addresses set it to `::,0.0.0.0`,
5051
dbName?: string, // by default generate random dbName
5152
dbPath?: string, // by default create in temp directory
5253
storageEngine?: string, // by default `ephemeralForTest`

src/MongoMemoryServer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ tmp.setGracefulCleanup();
1212
export type MongoMemoryServerOptsT = {
1313
instance: {
1414
port?: ?number,
15+
ip?: string, // for binding to all IP addresses set it to `::,0.0.0.0`, by default '127.0.0.1'
1516
dbPath?: string,
1617
dbName?: string,
1718
storageEngine?: string,

src/util/MongoInstance.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type MongodOps = {
1010
// instance options
1111
instance: {
1212
port: number,
13+
ip?: string, // for binding to all IP addresses set it to `::,0.0.0.0`, by default '127.0.0.1'
1314
storageEngine?: string,
1415
dbPath: string,
1516
debug?: boolean | Function,
@@ -74,9 +75,10 @@ export default class MongodbInstance {
7475
}
7576

7677
prepareCommandArgs(): string[] {
77-
const { port, storageEngine, dbPath } = this.opts.instance;
78+
const { ip, port, storageEngine, dbPath } = this.opts.instance;
7879

7980
const result = [];
81+
result.push('--bind_ip', ip || '127.0.0.1');
8082
if (port) result.push('--port', port.toString());
8183
if (storageEngine) result.push('--storageEngine', storageEngine);
8284
if (dbPath) result.push('--dbpath', dbPath);

src/util/__tests__/MongoInstance-test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ describe('MongoInstance', () => {
2525
},
2626
});
2727
expect(inst.prepareCommandArgs()).toEqual([
28+
'--bind_ip',
29+
'127.0.0.1',
2830
'--port',
2931
'27333',
3032
'--storageEngine',

0 commit comments

Comments
 (0)