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

Commit

Permalink
fix(connection): default family to undefined rather than 4
Browse files Browse the repository at this point in the history
* fix(connection): default `family` to undefined rather than 4

ported from #230

* chore(package lock): remove package lock

* fix(connection): typo
  • Loading branch information
Jessica Lord authored and mbroadst committed Nov 21, 2017
1 parent 89de5fa commit c1b5e04
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lib/connection/connection.js
Expand Up @@ -46,7 +46,7 @@ var connections = {};
* @class
* @param {string} options.host The server host
* @param {number} options.port The server port
* @param {number} [options.family=4] Version of IP stack. Defaults to 4.
* @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.
* @param {boolean} [options.keepAlive=true] TCP Connection keep alive enabled
* @param {number} [options.keepAliveInitialDelay=300000] Initial delay before TCP keep alive enabled
* @param {boolean} [options.noDelay=true] TCP Connection no delay
Expand Down Expand Up @@ -104,7 +104,7 @@ var Connection = function(messageHandler, options) {
// Default options
this.port = options.port || 27017;
this.host = options.host || 'localhost';
this.family = typeof options.family === 'number' ? options.family : 4;
this.family = typeof options.family === 'number' ? options.family : void 0;
this.keepAlive = typeof options.keepAlive === 'boolean' ? options.keepAlive : true;
this.keepAliveInitialDelay =
typeof options.keepAliveInitialDelay === 'number' ? options.keepAliveInitialDelay : 300000;
Expand Down Expand Up @@ -542,9 +542,15 @@ Connection.prototype.connect = function(_options) {
}

// Create new connection instance
var connection_options = self.domainSocket
? { path: self.host }
: { port: self.port, host: self.host, family: self.family };
var connection_options;
if (self.domainSocket) {
connection_options = { path: self.host };
} else {
connection_options = { port: self.port, host: self.host };
if (self.family !== void 0) {
connection_options.family = self.family;
}
}
self.connection = net.createConnection(connection_options);

// Set the options for the connection
Expand Down

0 comments on commit c1b5e04

Please sign in to comment.