Class: Connection


A class representing a single connection to a MongoDB server

new Connection(socket, options)

Creates a new Connection instance

Name Type Description
socket Socket

The socket this connection wraps

options Object optional

Optional settings

Name Type Default Description
host string optional

The host the socket is connected to

port number optional

The port used for the socket connection

keepAlive boolean true optional

TCP Connection keep alive enabled

keepAliveInitialDelay number 300000 optional

Initial delay before TCP keep alive enabled

connectionTimeout number 30000 optional

TCP Connection timeout setting

socketTimeout number 360000 optional

TCP Socket timeout setting

promoteLongs boolean optional

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

promoteValues boolean optional

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

promoteBuffers boolean optional

Promotes Binary BSON values to native Node Buffers.



Destroy connection


Is the connection connected

Return json object of connection

Return id of connection as a string

Unref this connection

Write to connection

Name Type Description
command Command

Command to write out need to implement toBin and toBinUnified


The server connection closed, all pool connections closed


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


The server connection caused an error, all pool connections closed


An event emitted each time the connection receives a parsed message from the wire


The driver experienced an invalid message, all pool connections closed


The server connection timed out, all pool connections closed