@@ -7,7 +7,7 @@ Specify Connection Options
7
7
.. contents:: On this page
8
8
:local:
9
9
:backlinks: none
10
- :depth: 1
10
+ :depth: 2
11
11
:class: singlecol
12
12
13
13
.. facet::
@@ -80,7 +80,7 @@ Network Compression
80
80
* - Connection Option
81
81
- Description
82
82
83
- * - ** compressors**
83
+ * - `` compressors``
84
84
- | The preferred compression types, in order, for wire-protocol messages sent to
85
85
| or received from the server. The driver uses the first of these compression types
86
86
| that the server supports.
@@ -90,7 +90,7 @@ Network Compression
90
90
| **MongoClient Example**: ``compressors = "snappy,zstd,zlib"``
91
91
| **Connection URI Example**: ``compressors=snappy,zstd,zlib``
92
92
93
- * - ** zlibCompressionLevel**
93
+ * - `` zlibCompressionLevel``
94
94
- | The compression level for zlib to use. This option accepts
95
95
| an integer value between ``-1`` and ``9``:
96
96
|
@@ -114,7 +114,7 @@ Timeouts
114
114
* - Connection Option
115
115
- Description
116
116
117
- * - ** timeoutMS**
117
+ * - `` timeoutMS``
118
118
- | The number of milliseconds each driver operation must complete within. If an
119
119
| operation doesn't finish in the specified time, {+driver-short+} raises a timeout exception.
120
120
| For more information, see :ref:`<pymongo-csot>`.
@@ -134,7 +134,7 @@ Server Selection
134
134
* - Connection Option
135
135
- Description
136
136
137
- * - ** server_selector**
137
+ * - `` server_selector``
138
138
- | A user-defined Python function called by {+driver-short+} to choose the server
139
139
| to run an operation against. For more information, see
140
140
| :ref:`<pymongo-server-selection>`.
@@ -144,6 +144,91 @@ Server Selection
144
144
| **MongoClient Example**: ``server_selector = your_function``
145
145
| **Connection URI Example**: N/A
146
146
147
+ Connection Pools
148
+ ~~~~~~~~~~~~~~~~
149
+
150
+ A **connection pool** is a cache of open database connections maintained by {+driver-short+}.
151
+ When your application requests a connection to MongoDB, {+driver-short+}
152
+ gets a connection from the pool, performs operations, and returns the connection
153
+ to the pool for reuse. Connection pools help reduce application latency and the number
154
+ of times that {+driver-short+} must create new connections.
155
+
156
+ To learn more about connection pools, see
157
+ :manual:`Connection Pool Overview </administration/connection-pool-overview/>`
158
+ in the {+mdb-server+} manual.
159
+
160
+ .. list-table::
161
+ :widths: 30 70
162
+ :header-rows: 1
163
+
164
+ * - Setting
165
+ - Description
166
+
167
+ * - ``connectTimeoutMS``
168
+ - | The time that {+driver-short+} waits when connecting a new
169
+ socket before timing out.
170
+ |
171
+ | **Data Type**: ``int``
172
+ | **Default**: ``20000``
173
+ | **MongoClient Example**: ``connectTimeoutMS = 40000``
174
+ | **Connection URI Example**: ``connectTimeoutMS=40000``
175
+
176
+ * - ``maxConnecting``
177
+ - | The maximum number of connections that each pool can establish concurrently.
178
+ If this limit is reached, further requests wait until a connection is established
179
+ or another in-use connection is checked back into the pool.
180
+ |
181
+ | **Data Type**: ``int``
182
+ | **Default**: ``2``
183
+ | **MongoClient Example**: ``maxConnecting = 3``
184
+ | **Connection URI Example**: ``maxConnecting=3``
185
+
186
+ * - ``maxIdleTimeMS``
187
+ - | The maximum time that a connection can remain idle in the pool.
188
+ |
189
+ | **Data Type**: ``int``
190
+ | **Default**: ``None`` (no limit)
191
+ | **MongoClient Example**: ``maxIdleTimeMS = 60000``
192
+ | **Connection URI Example**: ``maxIdleTimeMS=60000``
193
+
194
+ * - ``maxPoolSize``
195
+ - | The maximum number of concurrent connections that the pool maintains.
196
+ If the maximum pool size is reached, further requests wait until a connection
197
+ becomes available.
198
+ |
199
+ | **Data Type**: ``int``
200
+ | **Default**: ``100``
201
+ | **MongoClient Example**: ``maxPoolSize = 150``
202
+ | **Connection URI Example**: ``maxPoolSize=150``
203
+
204
+ * - ``minPoolSize``
205
+ - | The minimum number of concurrent connections that the pool maintains. If
206
+ the number of open connections falls below this value due to network errors,
207
+ {+driver-short+} attempts to create new connections to maintain this minimum.
208
+ |
209
+ | **Data Type**: ``int``
210
+ | **Default**: ``0``
211
+ | **MongoClient Example**: ``minPoolSize = 3``
212
+ | **Connection URI Example**: ``minPoolSize=3``
213
+
214
+ * - ``socketTimeoutMS``
215
+ - | The length of time that {+driver-short+} waits for a response from the server
216
+ before timing out.
217
+ |
218
+ | **Data Type**: ``int``
219
+ | **Default**: ``None`` (no timeout)
220
+ | **MongoClient Example**: ``socketTimeoutMS = 100000``
221
+ | **Connection URI Example**: ``socketTimeoutMS=100000``
222
+
223
+ * - ``waitQueueTimeoutMS``
224
+ - | How long a thread waits for a connection to become available in the connection pool
225
+ before timing out.
226
+ |
227
+ | **Data Type**: ``int``
228
+ | **Default**: ``None`` (no timeout)
229
+ | **MongoClient Example**: ``waitQueueTimeoutMS = 100000``
230
+ | **Connection URI Example**: ``waitQueueTimeoutMS=100000``
231
+
147
232
Authentication
148
233
~~~~~~~~~~~~~~
149
234
@@ -154,7 +239,7 @@ Authentication
154
239
* - Connection Option
155
240
- Description
156
241
157
- * - ** authMechanism**
242
+ * - `` authMechanism``
158
243
- | The mechanism {+driver-short+} uses to authenticate the application. Valid
159
244
| options are defined in `MECHANISMS. <{+api-root+}pymongo/database.html#pymongo.auth.MECHANISMS>`__
160
245
|
@@ -164,7 +249,7 @@ Authentication
164
249
| **MongoClient Example**: ``authMechanism = "MONGODB-X509"``
165
250
| **Connection URI Example**: ``authMechanism=MONGODB-X509``
166
251
167
- * - ** authMechanismProperties**
252
+ * - `` authMechanismProperties``
168
253
- | Options specific to the authentication mechanism. Not needed for all authentication
169
254
| mechanisms.
170
255
|
@@ -173,15 +258,15 @@ Authentication
173
258
| **MongoClient Example**: ``authMechanismProperties = "AWS_SESSION_TOKEN:12345"``
174
259
| **Connection URI Example**: ``authMechanismProperties=AWS_SESSION_TOKEN:12435``
175
260
176
- * - ** authSource**
261
+ * - `` authSource``
177
262
- | The database to authenticate against.
178
263
|
179
264
| **Data Type**: {+string-data-type+}
180
265
| **Default**: The database in the connection URI, or ``"admin"`` if none is provided
181
266
| **MongoClient Example**: ``authSource = "admin"``
182
267
| **Connection URI Example**: ``authSource=admin``
183
268
184
- * - ** username**
269
+ * - `` username``
185
270
- | The username for authentication. When this option is included in a connection
186
271
| URI, you must percent-escape it.
187
272
|
@@ -190,7 +275,7 @@ Authentication
190
275
| **MongoClient Example**: ``username = "my user"``
191
276
| **Connection URI Example**: ``username=my+user``
192
277
193
- * - ** password**
278
+ * - `` password``
194
279
- | The password for authentication. When this option is included in a connection
195
280
| URI, you must percent-escape it.
196
281
|
@@ -211,39 +296,39 @@ Read and Write Operations
211
296
* - Connection Option
212
297
- Description
213
298
214
- * - ** replicaSet**
299
+ * - `` replicaSet``
215
300
- | Specifies the name of the replica set to connect to.
216
301
|
217
302
| **Data Type**: {+string-data-type+}
218
303
| **Default**: ``null``
219
304
| **MongoClient Example**: ``replicaSet='replicaSetName'``
220
305
| **Connection URI Example**: ``replicaSet=replicaSetName``
221
306
222
- * - ** directConnection**
307
+ * - `` directConnection``
223
308
- | Whether to connect only to the primary member of the replica set.
224
309
|
225
310
| **Data Type**: {+bool-data-type+}
226
311
| **Default**: ``False``
227
312
| **MongoClient Example**: ``directConnection=True``
228
313
| **Connection URI Example**: ``directConnection=true``
229
314
230
- * - ** readPreference**
315
+ * - `` readPreference``
231
316
- | Specifies the client's read-preference settings.
232
317
|
233
318
| **Data Type**: `read_preferences <{+api-root+}pymongo/read_preferences.html#pymongo.read_preferences>`__
234
319
| **Default**: ``ReadPreference.Primary``
235
320
| **MongoClient Example**: ``readPreference=ReadPreference.SECONDARY_PREFERRED``
236
321
| **Connection URI Example**: ``readPreference=secondaryPreferred``
237
322
238
- * - ** readConcern**
323
+ * - `` readConcern``
239
324
- | Specifies the client's read-concern settings. For more information, see :manual:`</reference/read-concern/>`.
240
325
|
241
326
| **Data Type**: {+string-data-type+}
242
327
| **Default**: ``None``
243
328
| **MongoClient Example**: ``readConcern="majority"``
244
329
| **Connection URI Example**: ``readConcern=majority``
245
330
246
- * - ** writeConcern**
331
+ * - `` writeConcern``
247
332
- | Specifies the client's write-concern settings. For more information, see
248
333
:manual:`</reference/write-concern/>`.
249
334
|
@@ -252,7 +337,7 @@ Read and Write Operations
252
337
| **MongoClient Example**: ``writeConcern="majority"``
253
338
| **Connection URI Example**: ``writeConcern=majority``
254
339
255
- * - ** localThresholdMS**
340
+ * - `` localThresholdMS``
256
341
- | The latency window for a replica-set members eligibility. If a member's
257
342
round trip ping takes longer than the fastest server's round-trip ping
258
343
time plus this value, the server isn't eligible for selection.
@@ -262,7 +347,7 @@ Read and Write Operations
262
347
| **MongoClient Example**: ``localThresholdMS=35``
263
348
| **Connection URI Example**: ``localThresholdMS=35``
264
349
265
- * - ** retryReads**
350
+ * - `` retryReads``
266
351
- | Specifies whether the client retries supported read operations. For more
267
352
information, see :manual:`Retryable Reads </core/retryable-reads/>` in the {+mdb-server+}
268
353
manual.
@@ -272,7 +357,7 @@ Read and Write Operations
272
357
| **MongoClient Example**: ``retryReads=False``
273
358
| **Connection URI Example**: ``retryReads=false``
274
359
275
- * - ** retryWrites**
360
+ * - `` retryWrites``
276
361
- | Specifies whether the client retries supported write operations. For more
277
362
information, see :manual:`Retryable Writes </core/retryable-writes/>` in the {+mdb-server+}
278
363
manual.
0 commit comments