The main purpose of the MongoDB connection model is to be a domain model around a MongoDB connection. It encapsulates generating a Connection String URI from a group of attributes and parses URI using the MongoDB Node.JS Driver URI Parser.
MongoDB connection model is based on Ampersand.js framework and consist of props and derived props. The props object describes the observable properties that MongoDB connection model gets from the Node.js Driver API.
Specifies the name of the replica set, if the mongod is a member of a replica set
undefined
connectTimeoutMS
Number
The time in milliseconds to attempt a connection before timing out
undefined
socketTimeoutMS
Number
The time in milliseconds to attempt a send or receive on a socket before the attempt times out
undefined
compression
Object
Object includes compressors and a compression level. The following compressors can be specified: snappy, zlib (Available in MongoDB 3.6 or greater)
undefined
Connection Pool Option
Property
Type
Description
Default
maxPoolSize
Number
The maximum number of connections in the connection pool
undefined
minPoolSize
Number
The minimum number of connections in the connection pool
undefined
maxIdleTimeMS
Number
The maximum number of milliseconds that a connection can remain idle in the pool before being removed and closed
undefined
waitQueueMultiple
Number
A number that the driver multiples the maxPoolSize value to, to provide the maximum number of threads allowed to wait for a connection to become available from the pool
undefined
waitQueueTimeoutMS
Number
The maximum time in milliseconds that a thread can wait for a connection to become available
Specifies the read preferences for this connection. Possible values: PRIMARY, PRIMARY_PREFERRED, SECONDARY, SECONDARY_PREFERRED, NEAREST
PRIMARY
maxStalenessSeconds
Number
Specifies, in seconds, how stale a secondary can be before the client stops using it for read operations
undefined
readPreferenceTags
Object
Default read preference tags for the client
undefined
Authentication Options
Property
Type
Description
Default
authSource
String
Specify the database name associated with the user’s credentials
undefined
authMechanism
String
Specifies the authentication mechanism that MongoDB will use to authenticate the connection. Possible values: DEFAULT, GSSAPI, MONGODB-X509, PLAIN, SCRAM-SHA-256
undefined
authMechanismProperties
Object
Additional options provided for authentication (e.g. to enable hostname canonicalization for GSSAPI)
undefined
gssapiServiceName
String
Set the Kerberos service name when connecting to Kerberized MongoDB instances
undefined
gssapiServiceRealm
String
Set the Realm service name
undefined
gssapiCanonicalizeHostName
Boolean
Whether canonicalized hostname
undefined
Server Selection and Discovery Options
Property
Type
Description
Default
localThresholdMS
Number
The size (in milliseconds) of the latency window for selecting among multiple suitable MongoDB instances
undefined
serverSelectionTimeoutMS
Number
Specifies how long (in milliseconds) to block for server selection before throwing an exception
undefined
serverSelectionTryOnce
Boolean
Instructs the driver to scan the MongoDB deployment exactly once after server selection fails and then either select a server or raise an error
undefined
heartbeatFrequencyMS
Number
Controls when the driver checks the state of the MongoDB deployment
undefined
Miscellaneous Configuration
Property
Type
Description
Default
appname
String
An application name passed to server as client metadata
undefined
retryWrites
Boolean
Enable retryable writes
undefined
uuidRepresentation
String
The legacy representation of UUID. Possible values: standard, csharpLegacy, javaLegacy, pythonLegacy
UNVALIDATED - Use SSL but do not perform any validation of the certificate chain. See also node.js driver "No Certificate Validation" docs. Very not recommended and likely to be deprecated in future releases because it exposes potential Man-In-The-Middle attack vectors.
Because authentication is quite difficult for operators to migrate to, the most common method of securing a MongoDB deployment is to use an SSH tunnel. This allows operators to leverage their existing SSH security infrastructure to also provide secure access to MongoDB. For a standard deployment of MongoDB on AWS, this is almost always to strategy. Because of this, we now support creating SSH tunnels automatically when connecting to MongoDB.
The above provides the same functionality as creating the tunnel using the bash
command below and connecting to MongoDB via another terminal. Notice that
connection-model uses a random local port each time it creates a tunnel.
Using the command line, you'd have to replace <random port> with an actual
port number.