Class: ReplSet

ReplSet

Creates a new ReplSet instance

new ReplSet(servers, options){ReplSet}

Name Type Description
servers Array.<Server>

A seedlist of servers participating in the replicaset.

options object optional

Optional settings.

Name Type Default Description
ha boolean true optional

Turn on high availability monitoring.

haInterval number 10000 optional

Time between each replicaset status check.

replicaSet string optional

The name of the replicaset to connect to.

secondaryAcceptableLatencyMS number 15 optional

Sets the range of servers to pick when using NEAREST (lowest ping ms + the latency fence, ex: range of 1 to (1 + 15) ms)

connectWithNoPrimary boolean false optional

Sets if the driver should connect even if no primary is available

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)

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.

sslValidate boolean false optional

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

sslCA array 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 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 optional

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

ciphers string optional

Passed directly through to tls.createSecureContext. See https://nodejs.org/dist/latest-v9.x/docs/api/tls.html#tls_tls_createsecurecontext_options for more info.

ecdhCurve string optional

Passed directly through to tls.createSecureContext. See https://nodejs.org/dist/latest-v9.x/docs/api/tls.html#tls_tls_createsecurecontext_options for more info.

sslKey Buffer | string 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 optional

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

servername string optional

String containing the server name requested via TLS SNI.

socketOptions object optional

Socket options

Name Type Default Description
noDelay boolean true optional

TCP Socket NoDelay option.

keepAlive boolean true optional

TCP Connection keep alive enabled

keepAliveInitialDelay number 120000 optional

The number of milliseconds to wait before initiating keepAlive on the TCP socket

connectTimeoutMS number 10000 optional

How long to wait for a connection to be established before timing out

socketTimeoutMS number 360000 optional

How long a send or receive on a socket can take before timing out

domainsEnabled boolean false optional

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

maxStalenessSeconds number optional

The max staleness to secondary reads (values under 10 seconds cannot be guaranteed);

monitorCommands boolean false optional

Enable command monitoring for this topology

Properties:
Name Type Description
parserType string

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

Deprecated
  • Yes
Fires:
Returns:
ReplSet instance.

Events

ReplSet close event

Type:
  • object

An event emitted indicating a command failed, if command monitoring is enabled

Type:
  • object

An event emitted indicating a command was started, if command monitoring is enabled

Type:
  • object

An event emitted indicating a command succeeded, if command monitoring is enabled

Type:
  • object

A replset connect event, used to verify that the connection is up and running

Type:

ReplSet error event, emitted if there is an error listener.

Type:

ReplSet fullsetup event, emitted when all servers in the topology have been connected to.

Type:
  • Replset

The replset high availability event

Type:
  • function
Name Type Description
type string

The stage in the high availability event (start|end)

data.norepeat boolean

This is a repeating high availability process or a single execution only

data.id number

The id for this high availability request

data.state object

An object containing the information about the current replicaset

A server member joined the replicaset

Type:
  • function
Name Type Description
type string

The type of member that joined (primary|secondary|arbiter)

server Server

The server object that joined

A server member left the replicaset

Type:
  • function
Name Type Description
type string

The type of member that left (primary|secondary|arbiter)

server Server

The server object that left

ReplSet open event, emitted when replicaset can start processing commands.

Type:
  • Replset

ReplSet parseError event

Type:
  • object

ReplSet timeout event

Type:
  • object