Class: Mongos

Mongos

new Mongos(seedlist){Mongos}

Creates a new Mongos instance

Name Type Default Description
seedlist array

A list of seeds for the replicaset

options.haInterval number 5000 optional

The High availability period for replicaset inquiry

options.cursorFactory Cursor Cursor optional

The cursor factory class used for all query cursors

options.size number 5 optional

Server connection pool size

options.keepAlive boolean true optional

TCP Connection keep alive enabled

options.keepAliveInitialDelay number 0 optional

Initial delay before TCP keep alive enabled

options.localThresholdMS number 15 optional

Cutoff latency point in MS for MongoS proxy selection

options.noDelay boolean true optional

TCP Connection no delay

options.connectionTimeout number 1000 optional

TCP Connection timeout setting

options.socketTimeout number 0 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.servername string null optional

String containing the server name requested via TLS SNI.

options.rejectUnauthorized boolean true optional

Reject unauthorized server certificates

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.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.connection Connection optional

Specify connection object to execute command against

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

Initiate server connect

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.force boolean false optional

Force destroy the pool

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

options.retryWrites boolean optional

Enable retryable writes for this 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

options.retryWrites boolean optional

Enable retryable writes for this operation

callback opResultCallback

A callback function

selectServer(selector, callback)

Selects a server

Name Type Description
selector function

Unused

options.readPreference ReadPreference optional

Unused

options.session ClientSession optional

Specify a session if it is being used

callback function

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

options.retryWrites boolean optional

Enable retryable writes for this operation

callback opResultCallback

A callback function

Events

A mongos all event, used to signal that all topology members have been contacted.

Type:

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 mongos connect event, used to verify that the connection is up and running

Type:

A mongos fullsetup event, used to signal that all topology members have been contacted.

Type:

A server member joined the mongos list

Type:
Name Type Description
type string

The type of member that left (mongos)

server Server

The server object that joined

A server member left the mongos list

Type:
Name Type Description
type string

The type of member that left (mongos)

server Server

The server object that left

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

Type:

A server closed SDAM monitoring event

Type:
  • object

serverDescriptionChanged

A server description SDAM change monitoring event

Type:
  • object

serverHeartbeatFailed

A topology serverHeartbeatFailed SDAM event

Type:
  • object

serverHeartbeatStarted

A topology serverHeartbeatStarted SDAM event

Type:
  • object

serverHeartbeatSucceeded

A topology serverHeartbeatSucceeded SDAM change 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