mongoc_uri_t
Synopsis
typedef struct _mongoc_uri_t mongoc_uri_t;
Description
mongoc_uri_t provides an abstraction on top of the MongoDB connection URI format. It provides standardized parsing as well as convenience methods for extracting useful information such as replica hosts or authorization information.
See Connection String URI Reference on the MongoDB website for more information.
Format
mongodb:// <1> [username:password@] <2> host1 <3> [:port1] <4> [,host2[:port2],...[,hostN[:portN]]] <5> [/[database] <6> [?options]] <7>
mongodb is the specifier of the MongoDB protocol.
An optional username and password.
The only required part of the uri. This specifies either a hostname, IP address or UNIX domain socket.
An optional port number. Defaults to :27017.
Extra optional hosts and ports. You would specify multiple hosts, for example, for connections to replica sets.
The name of the database to authenticate if the connection string includes authentication credentials. If /database is not specified and the connection string includes credentials, defaults to the 'admin' database.
Connection specific options.
Replica Set Example
To describe a connection to a replica set named 'test' with the following mongod hosts:
db1.example.com on port 27017
db2.example.com on port 2500
You would use the connection string that resembles the following.
mongodb://db1.example.com,db2.example.com:2500/?replicaSet=test
Connection Options
ssl |
{true|false}, idicating if SSL must be used. |
connectTimeoutMS |
A timeout in milliseconds to attempt a connection before timing out. The default is no timeout. |
socketTimeoutMS |
The time in milliseconds to attempt to send or receive on a socket before the attempt times out. The default is 5 minutes. |
Connection Pool Options
maxPoolSize |
The maximum number of connections in the pool. The default value is 100. |
minPoolSize |
The minimum number of connections in the connection pool. Default value is 0. These are lazily created. |
maxIdleTimeMS |
Not implemented. |
waitQueueMultiple |
Not implemented. |
waitQueueTimeoutMS |
Not implemented. |
Write Concern Options
w |
|
||||||||||||
wtimeoutMS |
The time in milliseconds to wait for replication to succeed, as specified in the w option, before timing out. When wtimeoutMS is 0, write operations will never time out. |
||||||||||||
journal |
Controls whether write operations will wait until the mongod acknowledges the write operations and commits the data to the on disk journal.
|
Read Preference Options
readPreference |
Specifies the replica set read preference for this connection. This setting overrides any slaveOk value. The read preference values are the following:
|
readPreferenceTags |
Specifies a tag set as a comma-seperated list of colon-separted key-value pairs. |