Skip to content
This repository was archived by the owner on Feb 4, 2022. It is now read-only.

Commit 9b35583

Browse files
author
Jessica Lord
authored
Merge pull request #230 from mongodb-js/vkarpov15-patch-1
fix(connection): default `family` to undefined rather than 4
2 parents c841eb5 + 09916ae commit 9b35583

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: lib/connection/connection.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var connections = {};
2323
* @class
2424
* @param {string} options.host The server host
2525
* @param {number} options.port The server port
26-
* @param {number} [options.family=4] Version of IP stack. Defaults to 4.
26+
* @param {number} [options.family=null] IP version for DNS lookup, passed down to Node's [`dns.lookup()` function](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback). If set to `6`, will only look for ipv6 addresses.
2727
* @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
2828
* @param {number} [options.keepAliveInitialDelay=300000] Initial delay before TCP keep alive enabled
2929
* @param {boolean} [options.noDelay=true] TCP Connection no delay
@@ -74,7 +74,7 @@ var Connection = function(messageHandler, options) {
7474
// Default options
7575
this.port = options.port || 27017;
7676
this.host = options.host || 'localhost';
77-
this.family = typeof options.family == 'number' ? options.family : 4;
77+
this.family = typeof options.family == 'number' ? options.family : void 0;
7878
this.keepAlive = typeof options.keepAlive == 'boolean' ? options.keepAlive : true;
7979
this.keepAliveInitialDelay = typeof options.keepAliveInitialDelay == 'number'
8080
? options.keepAliveInitialDelay : 300000;
@@ -406,9 +406,15 @@ Connection.prototype.connect = function(_options) {
406406
}
407407

408408
// Create new connection instance
409-
var connection_options = self.domainSocket
410-
? {path: self.host}
411-
: {port: self.port, host: self.host, family: self.family};
409+
var connection_options;
410+
if (self.domainSocket) {
411+
connection_options = {path: self.host};
412+
} else {
413+
connection_options = {port: self.port, host: self.host};
414+
if (self.family !== void 0) {
415+
connection_options.family = self.family;
416+
}
417+
}
412418
self.connection = net.createConnection(connection_options);
413419

414420
// Set the options for the connection

0 commit comments

Comments
 (0)