@@ -12,12 +12,16 @@ applications and MongoDB instances in the official MongoDB :doc:`drivers
12
12
13
13
When you connect to a MongoDB database server, the MongoDB driver creates a
14
14
connection object that is instantiated once and then reused for every
15
- operation during the lifetime of the connection. The connection object
15
+ operation during the lifetime of the connection.
16
+ A single connection object can represent multiple connections to
17
+ multiple :program:`mongod` or :program:`mongos` instances.
18
+
19
+ The connection object
16
20
uses the options you specify when creating the connection.
17
- The driver's reuse of the connection object saves on the costs of setup and
21
+ The reuse of the connection object saves on the costs of setup and
18
22
teardown on connections.
19
23
20
- Beginning with the Fall 2012 driver release , MongoDB uses two new connection classes for
24
+ Beginning with the Fall 2012 driver releases , MongoDB uses two new connection classes for
21
25
the creation of connection objects:
22
26
23
27
- ``MongoClient``: the standard connection class
@@ -27,24 +31,24 @@ the creation of connection objects:
27
31
a separate class for connections to replica sets. See the
28
32
:doc:`drivers </applications/drivers>` documentation for details.
29
33
30
- In MongoDB versions prior to the Fall 2012 driver release , the connection classes vary from driver
34
+ In MongoDB versions prior to the Fall 2012 driver releases , the connection classes vary from driver
31
35
to driver.
32
36
33
- You connect to a MongoDB database server by starting a :program:`mongod`
34
- instance through a MongoDB :doc:`driver </applications/drivers>` or
35
- through the :program:`mongo` shell.
36
-
37
- Upon connection to the server, :program:`mongod` displays logging
37
+ When you start a :program:`mongod` or :program:`mongos` instance,
38
+ the program displays logging
38
39
information and then displays that it is waiting for a client
39
- connections , as shown in the following example.
40
+ connection , as shown in the following example.
40
41
41
42
.. code-block:: none
42
43
43
44
Wed Nov 21 12:56:58 [websvr] admin web console waiting for connections on port 28017
44
45
Wed Nov 21 12:56:58 [initandlisten] waiting for connections on port 27017
45
46
46
- By default, MongoDB waits for connections on port 27017. The
47
- :program:`mongod` program runs in either the foreground or background.
47
+ By default, MongoDB waits for connections on port 27017.
48
+
49
+ You make socket connections to running :program:`mongod` or :program:`mongos` instances
50
+ through a MongoDB :doc:`driver </applications/drivers>` or
51
+ through the :program:`mongo` shell.
48
52
49
53
.. note:: You *cannot* create a connection through HTTP on port 27017.
50
54
Specifically, you *cannot* connect to MongoDB by going to
@@ -67,8 +71,8 @@ The following is the standard URI connection scheme:
67
71
68
72
mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]
69
73
70
- .. example:: In the following example, a connection issued from a Java
71
- driver logs into two databases in the ``test`` replica set:
74
+ .. example:: In the following example, a connection
75
+ logs into two members in the ``test`` replica set:
72
76
73
77
.. code-block:: none
74
78
@@ -118,8 +122,8 @@ Connection options are name=value pairs. The pairs are separated by "&".
118
122
For backwards compatibility, ``;`` is accepted as a separator. But ``;``
119
123
is deprecated.
120
124
121
- .. example:: In the following example, a connection issued from a Java
122
- driver uses the ``replicaSet`` and ``connectTimeoutMS`` options.
125
+ .. example:: In the following example, a connection
126
+ uses the ``replicaSet`` and ``connectTimeoutMS`` options.
123
127
124
128
.. code-block:: none
125
129
@@ -128,31 +132,40 @@ is deprecated.
128
132
Replica Set Options
129
133
~~~~~~~~~~~~~~~~~~~
130
134
131
- .. data:: replicaSet=<name>
135
+ .. data:: replicaSet
132
136
133
- If the :program:`mongod` is a member of a :term:`replica set`, the
134
- name of the replica set.
137
+ Specifies the name of the :term:`replica set`, if the
138
+ :program:`mongod` is a member of a replica set.
139
+
140
+ When connecting to a replica set it is important to give a seed list
141
+ of at least two :program:`mongod` instances.
135
142
136
143
Connection Options
137
144
~~~~~~~~~~~~~~~~~~
138
145
139
- .. data:: ssl=<true,false,prefer>
146
+ .. data:: ssl
140
147
141
148
``true``: Initiate the connection with SSL.
142
149
143
150
``false``: Initiate the connection without SSL.
144
151
145
- ``prefer``: Initiate the connection with SSL, but if that fails initiate without SSL.
152
+ .. todo Determine whether ``prefer`` option exists. Check with server
153
+ team whether it's possible to do rolling restarts of a cluster to
154
+ turn on SSL. Here is the option
155
+ ``prefer``: Initiate the connection with SSL, but if that fails initiate without SSL.
146
156
147
157
The default value is ``false``.
148
158
149
- .. data:: connectTimeoutMS=<milliseconds>
159
+ .. note:: The :data:`ssl` option is not supported by all drivers. For information on your
160
+ driver, see the :doc:`drivers </applications/drivers>` documentation.
161
+
162
+ .. data:: connectTimeoutMS
150
163
151
164
The time in milliseconds to attempt a connection before timing out.
152
165
The default is never to timeout, though different drivers might vary.
153
166
See the :doc:`/applications/drivers` documentation.
154
167
155
- .. data:: socketTimeoutMS=<milliseconds>
168
+ .. data:: socketTimeoutMS
156
169
157
170
The time in milliseconds to attempt a send or receive on a socket
158
171
before the attempt times out. The default is never to timeout, though
@@ -168,29 +181,33 @@ Most drivers handle this for you behind the scenes. Some drivers do not
168
181
support connection pools. See the :doc:`/applications/drivers`
169
182
documentation.
170
183
171
- .. data:: maxPoolSize=<number>
184
+ .. data:: maxPoolSize
172
185
173
186
The maximum number of connections in the connection pool. The default
174
187
value is ``100``.
175
188
176
- .. data:: minPoolSize=<number>
189
+ .. data:: minPoolSize
177
190
178
- The minimum number of connections in the connection pool The default
191
+ The minimum number of connections in the connection pool. The default
179
192
value is ``0``.
180
193
181
- .. data:: maxIdleTimeMS=<milliseconds>
194
+ .. note:: The :data:`minPoolSize` option is not supported by all
195
+ drivers. For information on your driver, see the :doc:`drivers
196
+ </applications/drivers>` documentation.
197
+
198
+ .. data:: maxIdleTimeMS
182
199
183
200
The maximum number of milliseconds that a connection can remain idle
184
201
in the pool before being removed and closed.
185
202
186
- .. data:: waitQueueMultiple=<milliseconds>
203
+ .. data:: waitQueueMultiple
187
204
188
205
A multiplier number that is multiplied with the
189
206
``maxPoolSize`` setting to give the maximum number of threads allowed
190
207
to wait for a connection to become available from the pool. For
191
208
default values, see the :doc:`/applications/drivers` documentation.
192
209
193
- .. data:: waitQueueTimeoutMS=<milliseconds>
210
+ .. data:: waitQueueTimeoutMS
194
211
195
212
The maximum time in milliseconds that a thread is allowed to wait for
196
213
a connection to become available. For
@@ -199,28 +216,15 @@ documentation.
199
216
Write Concern Options
200
217
~~~~~~~~~~~~~~~~~~~~~
201
218
202
- .. data:: fireAndForget=<true|false>
203
-
204
- ``false``: Sends a :dbcommand:`getLastError` command after
205
- every update to ensure that the update succeeded.
219
+ For a full explanation of write concern, see
220
+ :ref:`write-operations-write-concern`.
206
221
207
- ``true``: Does not send a :dbcommand:`getLastError` command after
208
- every update.
222
+ .. data:: w
209
223
210
- The default value depends on the connection class. Prior to the Fall
211
- 2012 driver release, the default value is ``true``, which disables
212
- write concern. For the ``MongoClient`` and ``MongoReplicaSetClient``
213
- classes new in the Fall 2012 driver release the default is ``false``.
214
-
215
- For the new ``MongoClient`` and ``MongoReplicaSetClient`` classes, if
216
- you enable ``fireAndForget`` but also enable write concern through
217
- the ``w`` option, MongoDB issues an exception about the conflict.
218
-
219
- .. data:: w=<number or string>
220
-
221
- Used by the :dbcommand:`getLastError` command either
222
- to configure write concern on members of :term:`replica sets <replica
223
- set>` *or* to disable write concern entirely.
224
+ Used by the :dbcommand:`getLastError` command either to configure
225
+ write concern on members of :term:`replica sets <replica set>` *or*
226
+ to disable write concern entirely. This option can take either a
227
+ number or a string as a value.
224
228
225
229
``0``: Disables write concern. If you disable write concern but
226
230
enable the :dbcommand:`getLastError` command's ``journal`` option, the
@@ -233,24 +237,20 @@ Write Concern Options
233
237
replicated to the specified number of replica set members, including
234
238
the primary. If you set ``w`` to a number that is greater than the
235
239
number of set members that hold data, MongoDB waits for the
236
- non-existent members become available, which means MongoDB blocks
237
- indefinitely.
240
+ non-existent members become available, which means the write
241
+ operation blocks indefinitely.
238
242
239
243
``majority``: Confirms that write operations have replicated to the
240
244
majority of set members.
241
245
242
246
``-1``: Turns off reporting of network errors.
243
247
244
- For the new ``MongoClient`` and ``MongoReplicaSetClient`` classes, if
245
- you enable write concern but also enable ``fireAndForget``, MongoDB
246
- issues an exception about the conflict.
247
-
248
- .. data:: wtimeoutMS=<milliseconds>
248
+ .. data:: wtimeoutMS
249
249
250
250
The time in milliseconds to wait for replication to succeed, as
251
251
specified in the ``w`` option, before timing out.
252
252
253
- .. data:: journal=<true|false>
253
+ .. data:: journal
254
254
255
255
``true``: Sync to journal.
256
256
@@ -270,12 +270,10 @@ Write Concern Options
270
270
Read Preference Options
271
271
~~~~~~~~~~~~~~~~~~~~~~~
272
272
273
- .. data:: slaveOk=<true|false>
273
+ For a full explanation of read preferences, see
274
+ :ref:`replica-set-read-preference`.
274
275
275
- Specifies whether a driver connected to a replica set sends reads
276
- to secondaries. The default setting is ``false``.
277
-
278
- .. data:: readPreference=<string>
276
+ .. data:: readPreference
279
277
280
278
Specifies the :term:`replica set` read preference for this
281
279
connection. This setting overrides any ``slaveOk`` value. The read
@@ -293,7 +291,7 @@ Read Preference Options
293
291
The default value is :readmode:`primary`, which sends all read
294
292
operations to the replica set's :term:`primary`.
295
293
296
- .. data:: readPreferenceTags=<string>
294
+ .. data:: readPreferenceTags
297
295
298
296
Specifies a tag set as a comma-separated list of
299
297
colon-separated key-value pairs. For example:
@@ -314,7 +312,7 @@ Read Preference Options
314
312
Miscellaneous Configuration
315
313
~~~~~~~~~~~~~~~~~~~~~~~~~~~
316
314
317
- .. data:: uuidRepresentation=<string>
315
+ .. data:: uuidRepresentation
318
316
319
317
``standard``: The standard binary representation.
320
318
@@ -327,6 +325,10 @@ Miscellaneous Configuration
327
325
For the default, see the :doc:`drivers </applications/drivers>`
328
326
documentation for your driver.
329
327
328
+ .. note:: The :data:`uuidRepresentation` option is not supported by
329
+ all drivers. For information on your driver, see the :doc:`drivers
330
+ </applications/drivers>` documentation.
331
+
330
332
.. _connections-connection-examples:
331
333
332
334
Examples
@@ -354,6 +356,10 @@ password ``moon``:
354
356
355
357
Connect to a UNIX domain socket:
356
358
359
+ .. note:: Not all drivers support UNIX domain sockets. For information
360
+ on your driver, see the :doc:`drivers </applications/drivers>`
361
+ documentation.
362
+
357
363
.. code-block:: none
358
364
359
365
mongodb:///tmp/mongodb-27017.sock
0 commit comments