Class: Server

Server

new Server(host, port, options){Server}

Creates a new Server instance

Name Type Default Description
host string

The host for the server, can be either an IP4, IP6 or domain socket style host.

port number optional

The server port if IP4.

options object null optional

Optional settings.

Name Type Default Description
poolSize number 5 optional

Number of connections in the connection pool for each server instance, set to 5 as default for legacy reasons.

ssl boolean false optional

Use ssl connection (needs to have a mongod server with ssl support)

sslValidate object true optional

Validate mongod server certificate against ca (needs to have a mongod server with ssl support, 2.4 or higher)

checkServerIdentity boolean | function true optional

Ensure we check server identify during SSL, set to false to disable checking. Only works for Node 0.12.x or higher. You can pass in a boolean or your own checkServerIdentity override function.

sslCA array null optional

Array of valid certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher)

sslCRL array null optional

Array of revocation certificates either as Buffers or Strings (needs to have a mongod server with ssl support, 2.4 or higher)

sslCert Buffer | string null optional

String or buffer containing the certificate we wish to present (needs to have a mongod server with ssl support, 2.4 or higher)

sslKey Buffer | string null optional

String or buffer containing the certificate private key we wish to present (needs to have a mongod server with ssl support, 2.4 or higher)

sslPass Buffer | string null optional

String or buffer containing the certificate password (needs to have a mongod server with ssl support, 2.4 or higher)

servername string null optional

String containing the server name requested via TLS SNI.

autoReconnect boolean true optional

Reconnect on error or timeout.

socketOptions object null optional

Socket options

Name Type Default Description
noDelay boolean true optional

TCP Socket NoDelay option.

keepAlive number 0 optional

TCP KeepAlive on the socket with a X ms delay before start.

connectTimeoutMS number 0 optional

TCP Connection timeout setting

socketTimeoutMS number 0 optional

TCP Socket timeout setting

reconnectTries number 30 optional

Server attempt to reconnect #times

reconnectInterval number 1000 optional

Server will wait # milliseconds between retries

monitoring number true optional

Triggers the server instance to call ismaster

haInterval number 10000 optional

The interval of calling ismaster when monitoring is enabled.

domainsEnabled boolean false optional

Enable the wrapping of the callback in the current domain, disabled by default to avoid perf hit.

Properties:
Name Type Description
parserType string

the parser type used (c++ or js).

Deprecated
  • Yes
Fires:
Returns:
Server instance.

Methods

connections(){array}

All raw connections

Unref all sockets

Events

Server close event

Type:
  • object

Server connect event

Type:
  • object

Server error event

Type:

parseError

Server parseError event

Type:
  • object

reconnect

Server reconnect event

Type:
  • object

Server timeout event

Type:
  • object