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

Commit c1b5e04

Browse files
Jessica Lordmbroadst
Jessica Lord
authored andcommittedNov 21, 2017
fix(connection): default family to undefined rather than 4
* fix(connection): default `family` to undefined rather than 4 ported from #230 * chore(package lock): remove package lock * fix(connection): typo
1 parent 89de5fa commit c1b5e04

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed
 

‎lib/connection/connection.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var connections = {};
4646
* @class
4747
* @param {string} options.host The server host
4848
* @param {number} options.port The server port
49-
* @param {number} [options.family=4] Version of IP stack. Defaults to 4.
49+
* @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.
5050
* @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
5151
* @param {number} [options.keepAliveInitialDelay=300000] Initial delay before TCP keep alive enabled
5252
* @param {boolean} [options.noDelay=true] TCP Connection no delay
@@ -104,7 +104,7 @@ var Connection = function(messageHandler, options) {
104104
// Default options
105105
this.port = options.port || 27017;
106106
this.host = options.host || 'localhost';
107-
this.family = typeof options.family === 'number' ? options.family : 4;
107+
this.family = typeof options.family === 'number' ? options.family : void 0;
108108
this.keepAlive = typeof options.keepAlive === 'boolean' ? options.keepAlive : true;
109109
this.keepAliveInitialDelay =
110110
typeof options.keepAliveInitialDelay === 'number' ? options.keepAliveInitialDelay : 300000;
@@ -542,9 +542,15 @@ Connection.prototype.connect = function(_options) {
542542
}
543543

544544
// Create new connection instance
545-
var connection_options = self.domainSocket
546-
? { path: self.host }
547-
: { port: self.port, host: self.host, family: self.family };
545+
var connection_options;
546+
if (self.domainSocket) {
547+
connection_options = { path: self.host };
548+
} else {
549+
connection_options = { port: self.port, host: self.host };
550+
if (self.family !== void 0) {
551+
connection_options.family = self.family;
552+
}
553+
}
548554
self.connection = net.createConnection(connection_options);
549555

550556
// Set the options for the connection

0 commit comments

Comments
 (0)
This repository has been archived.