Class: Server

Server

Creates a new Server instance

Name Type Default Description
options.reconnect boolean true optional

Server will attempt to reconnect on loss of connection

options.reconnectTries number 30 optional

Server attempt to reconnect #times

options.reconnectInterval number 1000 optional

Server will wait # milliseconds between retries

options.monitoring number true optional

Enable the server state monitoring (calling ismaster at monitoringInterval)

options.monitoringInterval number 5000 optional

The interval of calling ismaster when monitoring is enabled.

options.cursorFactory Cursor Cursor optional

The cursor factory class used for all query cursors

options.host string

The server host

options.port number

The server port

options.size number 5 optional

Server connection pool size

options.keepAlive boolean true optional

TCP Connection keep alive enabled

options.keepAliveInitialDelay number 300000 optional

Initial delay before TCP keep alive enabled

options.noDelay boolean true optional

TCP Connection no delay

options.connectionTimeout number 30000 optional

TCP Connection timeout setting

options.socketTimeout number 360000 optional

TCP Socket timeout setting

options.ssl boolean false optional

Use SSL for connection

options.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.

options.ca Buffer optional

SSL Certificate store binary buffer

options.crl Buffer optional

SSL Certificate revocation store binary buffer

options.cert Buffer optional

SSL Certificate binary buffer

options.key Buffer optional

SSL Key file binary buffer

options.passphrase string optional

SSL Certificate pass phrase

options.rejectUnauthorized boolean true optional

Reject unauthorized server certificates

options.servername string null optional

String containing the server name requested via TLS SNI.

options.promoteLongs boolean true optional

Convert Long values from the db into Numbers if they fit into 53 bits

options.promoteValues boolean true optional

Promotes BSON values to native types where possible, set to false to only receive wrapper types.

options.promoteBuffers boolean false optional

Promotes Binary BSON values to native Node Buffers.

options.appname string null optional

Application name, passed in on ismaster call and logged in mongod server logs. Maximum size 128 bytes.

options.domainsEnabled boolean false optional

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

options.monitorCommands boolean false optional

Enable command monitoring for this topology

Properties:
Name Type Description
type string

the topology type.

parserType string

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

Fires:
Returns:
cursor instance

Methods

auth(credentials, callback)

Authenticate the topology.

Name Type Description
credentials MongoCredentials

The credentials for authentication we are using

callback authResultCallback

A callback function

command(ns, cmd, callback)

Execute a command

Name Type Default Description
ns string

The MongoDB fully qualified namespace (ex: db1.collection1)

cmd object

The command hash

options.readPreference ReadPreference optional

Specify read preference if command supports it

options.serializeFunctions Boolean false optional

Specify if functions on an object should be serialized.

options.checkKeys Boolean false optional

Specify if the bson parser should validate keys.

options.ignoreUndefined Boolean false optional

Specify if the BSON serializer should ignore undefined fields.

options.fullResult Boolean false optional

Return the full envelope instead of just the result document.

options.session ClientSession null optional

Session to use for the operation

callback opResultCallback

A callback function

Initiate server connect

connections(){Array.<Connection>}

All raw connections

cursor(ns, cmd, options){Cursor}

Get a new cursor

Name Type Description
ns string

The MongoDB fully qualified namespace (ex: db1.collection1)

cmd object | Long

Can be either a command returning a cursor or a cursorId

options object optional

Options for the cursor

Name Type Default Description
batchSize object 0 optional

Batchsize for the operation

documents array [] optional

Initial documents list for cursor

readPreference ReadPreference optional

Specify read preference if command supports it

serializeFunctions Boolean false optional

Specify if functions on an object should be serialized.

ignoreUndefined Boolean false optional

Specify if the BSON serializer should ignore undefined fields.

session ClientSession null optional

Session to use for the operation

topology object optional

The internal topology of the created cursor

Destroy the server connection

Name Type Default Description
options.emitClose boolean false optional

Emit close event on destroy

options.emitDestroy boolean false optional

Emit destroy event on destroy

options.force boolean false optional

Force destroy the pool

equals(server){boolean}

Compare two server instances

Name Type Description
server Server

Server to compare equality against

getDescription(){object}

Get the server description

insert(ns, ops, callback)

Insert one or more documents

Name Type Default Description
ns string

The MongoDB fully qualified namespace (ex: db1.collection1)

ops array

An array of documents to insert

options.ordered boolean true optional

Execute in order or out of order

options.writeConcern object {} optional

Write concern for the operation

options.serializeFunctions Boolean false optional

Specify if functions on an object should be serialized.

options.ignoreUndefined Boolean false optional

Specify if the BSON serializer should ignore undefined fields.

options.session ClientSession null optional

Session to use for the operation

callback opResultCallback

A callback function

isConnected(){boolean}

Figure out if the server is connected

isDestroyed(){boolean}

Figure out if the server instance was destroyed by calling destroy

lastIsMaster(){object}

Returns the last known ismaster document for this server

remove(ns, ops, callback)

Perform one or more remove operations

Name Type Default Description
ns string

The MongoDB fully qualified namespace (ex: db1.collection1)

ops array

An array of removes

options.ordered boolean true optional

Execute in order or out of order

options.writeConcern object {} optional

Write concern for the operation

options.serializeFunctions Boolean false optional

Specify if functions on an object should be serialized.

options.ignoreUndefined Boolean false optional

Specify if the BSON serializer should ignore undefined fields.

options.session ClientSession null optional

Session to use for the operation

callback opResultCallback

A callback function

selectServer(selector){Server}

Selects a server

Name Type Description
selector function

Unused

options.readPreference ReadPreference optional

Unused

options.session ClientSession optional

Unused

Unref all connections belong to this server

update(ns, ops, callback)

Perform one or more update operations

Name Type Default Description
ns string

The MongoDB fully qualified namespace (ex: db1.collection1)

ops array

An array of updates

options.ordered boolean true optional

Execute in order or out of order

options.writeConcern object {} optional

Write concern for the operation

options.serializeFunctions Boolean false optional

Specify if functions on an object should be serialized.

options.ignoreUndefined Boolean false optional

Specify if the BSON serializer should ignore undefined fields.

options.session ClientSession null optional

Session to use for the operation

callback opResultCallback

A callback function

Events

Server connection pool closed

Type:
  • object

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

Type:

Server destroyed was called

Type:

Server connection pool caused an error

Type:
  • Error

A server reconnect event, used to verify that the server topology has reconnected

Type:

Server reconnect failed

Type:
  • Error

A server closed SDAM monitoring event

Type:
  • object

serverDescriptionChanged

A server description SDAM change monitoring event

Type:
  • object

A server opening SDAM monitoring event

Type:
  • object

A topology closed SDAM event

Type:
  • object

topologyDescriptionChanged

A topology structure SDAM change event

Type:
  • object

A topology open SDAM event

Type:
  • object