Skip to content

Commit 5a519a4

Browse files
committed
feedback
1 parent fa842ac commit 5a519a4

File tree

2 files changed

+72
-99
lines changed

2 files changed

+72
-99
lines changed

source/connect/connection-options.txt

Lines changed: 71 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ Using a MongoDB\\Client Object
5353

5454
You can pass connection options to the ``MongoDB\Client`` constructor
5555
instead of including them in your connection URI.
56-
Configuring the connection this way makes it easier to
57-
change settings at runtime and helps you catch errors during compilation.
5856

5957
The following example shows how to use the ``$uriOptions`` parameter of the
6058
``MongoDB\Client`` constructor to set connection options:
@@ -68,15 +66,30 @@ The following example shows how to use the ``$uriOptions`` parameter of the
6866

6967
.. note::
7068

71-
If you specify an option in both the ``MongoDB\Client`` object and in the connection
72-
URI, the value in the ``MongoDB\Client`` object takes precedence.
69+
If you specify an option in both the ``$uriOptions`` parameter and in the connection
70+
URI, the value in ``$uriOptions`` takes precedence.
7371

7472
Connection URI Options
7573
----------------------
7674

7775
The following sections describe the options that you can set for your connection to
7876
MongoDB. Each connection option links to its corresponding
79-
entry in the {+mdb-server+} manual.
77+
entry in the {+mdb-server+} manual.
78+
79+
.. important:: Percent-Encoding
80+
81+
If the value of a connection option contains special characters, you must
82+
:wikipedia:`percent-encode <Percent-encoding>` the value before including it
83+
in the connection URI. You can use the ``rawurlencode()`` method to encode
84+
these values according to the URI syntax specified in RFC 3986.
85+
86+
Don't percent-encode connection options when including them in the
87+
``$uriOptions`` parameter.
88+
89+
To learn more, see the following resources:
90+
91+
- `RFC 3986 <http://www.faqs.org/rfcs/rfc3986.html>`__
92+
- `rawurlencode <{+php-manual+}/rawurlencode>`__ in the PHP manual
8093

8194
Replica Set Options
8295
~~~~~~~~~~~~~~~~~~~
@@ -88,14 +101,14 @@ Replica Set Options
88101
* - Connection Option
89102
- Description
90103

91-
* - :manual:`directConnection </reference/connection-string/#mongodb-urioption-urioption.directConnection>`
104+
* - :manual:`directConnection </reference/connection-string-options/#mongodb-urioption-urioption.directConnection>`
92105
- | **Data Type**: {+bool-data-type+}
93-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'directConnection' => true ];``
106+
| **MongoDB\\Client Example**: ``$uriOptions = ['directConnection' => true];``
94107
| **Connection URI Example**: ``directConnection=true``
95108

96-
* - :manual:`replicaSet </reference/connection-string/#mongodb-urioption-urioption.replicaSet>`
109+
* - :manual:`replicaSet </reference/connection-string-options/#mongodb-urioption-urioption.replicaSet>`
97110
- | **Data Type**: {+string-data-type+}
98-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'replicaSet' => 'replicaSetName' ];``
111+
| **MongoDB\\Client Example**: ``$uriOptions = ['replicaSet' => 'replicaSetName'];``
99112
| **Connection URI Example**: ``replicaSet=replicaSetName``
100113

101114
Connection Options
@@ -116,14 +129,14 @@ Timeout Options
116129
* - Connection Option
117130
- Description
118131

119-
* - :manual:`connectTimeoutMS </reference/connection-string/#mongodb-urioption-urioption.connecttimeoutms>`
132+
* - :manual:`connectTimeoutMS </reference/connection-string-options/#mongodb-urioption-urioption.connecttimeoutms>`
120133
- | **Data Type**: {+int-data-type+}
121-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'connectTimeoutMS' => 20000 ];``
134+
| **MongoDB\\Client Example**: ``$uriOptions = ['connectTimeoutMS' => 20000];``
122135
| **Connection URI Example**: ``connectTimeoutMS=20000``
123136

124-
* - :manual:`socketTimeoutMS </reference/connection-string/#mongodb-urioption-urioption.sockettimeoutms>`
137+
* - :manual:`socketTimeoutMS </reference/connection-string-options/#mongodb-urioption-urioption.sockettimeoutms>`
125138
- | **Data Type**: {+int-data-type+}
126-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'socketTimeoutMS' => 400000 ];``
139+
| **MongoDB\\Client Example**: ``$uriOptions = ['socketTimeoutMS' => 400000];``
127140
| **Connection URI Example**: ``socketTimeoutMS=400000``
128141

129142
.. _php-compression-options:
@@ -138,36 +151,16 @@ Compression Options
138151
* - Connection Option
139152
- Description
140153

141-
* - :manual:`compressors </reference/connection-string/#mongodb-urioption-urioption.compressors>`
154+
* - :manual:`compressors </reference/connection-string-options/#mongodb-urioption-urioption.compressors>`
142155
- | **Data Type**: {+string-data-type+}
143-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'compressors' => 'snappy,zstd,zlib' ];``
156+
| **MongoDB\\Client Example**: ``$uriOptions = ['compressors' => 'snappy,zstd,zlib'];``
144157
| **Connection URI Example**: ``compressors=snappy,zstd,zlib``
145158

146-
* - :manual:`zlibCompressionLevel </reference/connection-string/#mongodb-urioption-urioption.zlibcompressionlevel>`
159+
* - :manual:`zlibCompressionLevel </reference/connection-string-options/#mongodb-urioption-urioption.zlibcompressionlevel>`
147160
- | **Data Type**: {+int-data-type+}
148-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'zlibCompressionLevel' => 3 ];``
161+
| **MongoDB\\Client Example**: ``$uriOptions = ['zlibCompressionLevel' => 3];``
149162
| **Connection URI Example**: ``zlibCompressionLevel=3``
150163

151-
Connection Pool Options
152-
~~~~~~~~~~~~~~~~~~~~~~~
153-
154-
.. list-table::
155-
:header-rows: 1
156-
:stub-columns: 1
157-
158-
* - Connection Option
159-
- Description
160-
161-
* - :manual:`maxPoolSize </reference/connection-string/#mongodb-urioption-urioption.maxpoolsize>`
162-
- | **Data Type**: {+int-data-type+}
163-
| **MongoDB\\Client Example**: N/A
164-
| **Connection URI Example**: ``maxPoolSize=75``
165-
166-
* - :manual:`waitQueueTimeoutMS </reference/connection-string/#mongodb-urioption-urioption.waitqueuetimeoutms>`
167-
- | **Data Type**: {+int-data-type+}
168-
| **MongoDB\\Client Example**: N/A
169-
| **Connection URI Example**: ``waitQueueTimeoutMS=10000``
170-
171164
Write Concern Options
172165
~~~~~~~~~~~~~~~~~~~~~
173166

@@ -178,19 +171,19 @@ Write Concern Options
178171
* - Connection Option
179172
- Description
180173

181-
* - :manual:`w </reference/connection-string/#mongodb-urioption-urioption.w>`
174+
* - :manual:`w </reference/connection-string-options/#mongodb-urioption-urioption.w>`
182175
- | **Data Type**: {+string-data-type+}
183-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'w' => 'majority' ];``
176+
| **MongoDB\\Client Example**: ``$uriOptions = ['w' => 'majority'];``
184177
| **Connection URI Example**: ``w=majority``
185178

186-
* - :manual:`wTimeoutMS </reference/connection-string/#mongodb-urioption-urioption.wtimeoutms>`
179+
* - :manual:`wTimeoutMS </reference/connection-string-options/#mongodb-urioption-urioption.wtimeoutms>`
187180
- | **Data Type**: {+int-data-type+}
188-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'wTimeoutMS' => 10000 ];``
181+
| **MongoDB\\Client Example**: ``$uriOptions = ['wTimeoutMS' => 10000];``
189182
| **Connection URI Example**: ``wTimeoutMS=10000``
190183

191-
* - :manual:`journal </reference/connection-string/#mongodb-urioption-urioption.journal>`
184+
* - :manual:`journal </reference/connection-string-options/#mongodb-urioption-urioption.journal>`
192185
- | **Data Type**: {+bool-data-type+}
193-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'journal' => true ];``
186+
| **MongoDB\\Client Example**: ``$uriOptions = ['journal' => true];``
194187
| **Connection URI Example**: ``journal=true``
195188

196189
Read Concern Options
@@ -203,9 +196,9 @@ Read Concern Options
203196
* - Connection Option
204197
- Description
205198

206-
* - :manual:`readConcernLevel </reference/connection-string/#mongodb-urioption-urioption.readconcernlevel>`
199+
* - :manual:`readConcernLevel </reference/connection-string-options/#mongodb-urioption-urioption.readconcernlevel>`
207200
- | **Data Type**: {+string-data-type+}
208-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'readConcernLevel' => 'majority' ];``
201+
| **MongoDB\\Client Example**: ``$uriOptions = ['readConcernLevel' => 'majority'];``
209202
| **Connection URI Example**: ``readConcernLevel=majority``
210203

211204
Read Preference Options
@@ -219,57 +212,36 @@ Read Preference Options
219212
* - Connection Option
220213
- Description
221214

222-
* - :manual:`readPreference </reference/connection-string/#mongodb-urioption-urioption.readpreference>`
215+
* - :manual:`readPreference </reference/connection-string-options/#mongodb-urioption-urioption.readpreference>`
223216
- | **Data Type**: `MongoDB\\Driver\\ReadPreference <https://www.php.net/manual/en/class.mongodb-driver-readpreference.php>`__
224-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'readPreference' => 'secondaryPreferred' ];``
217+
| **MongoDB\\Client Example**: ``$uriOptions = ['readPreference' => 'secondaryPreferred'];``
225218
| **Connection URI Example**: ``readPreference=secondaryPreferred``
226219

227-
* - :manual:`maxStalenessSeconds </reference/connection-string/#mongodb-urioption-urioption.maxstalenessseconds>`
220+
* - :manual:`maxStalenessSeconds </reference/connection-string-options/#mongodb-urioption-urioption.maxstalenessseconds>`
228221
- | **Data Type**: {+int-data-type+}
229-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'maxStalenessSeconds' => 30 ];``
222+
| **MongoDB\\Client Example**: ``$uriOptions = ['maxStalenessSeconds' => 30];``
230223
| **Connection URI Example**: ``maxStalenessSeconds=30``
231224

232-
* - :manual:`readPreferenceTags </reference/connection-string/#mongodb-urioption-urioption.readpreferencetags>`
225+
* - :manual:`readPreferenceTags </reference/connection-string-options/#mongodb-urioption-urioption.readpreferencetags>`
233226
- | **Data Type**: ``array``
234227
| **MongoDB\\Client Example**:
235228

236229
.. code-block:: php
237230

238231
$uriOptions = [
239-
'readPreferenceTags' => [
240-
[ 'region' => 'east' ],
241-
[ 'region' => 'west']
242-
]
243-
];``
232+
'readPreferenceTags' => [
233+
['dc' => 'ny', 'rack' => 'r1'],
234+
[],
235+
],
236+
];
244237

245-
**Connection URI Example**: ``readPreferenceTags=region:east,region:west``
238+
**Connection URI Example**: ``readPreferenceTags=dc:ny,rack:r1&readPreferenceTags=``
246239

247240
Authentication Options
248241
~~~~~~~~~~~~~~~~~~~~~~
249242

250-
.. list-table::
251-
:header-rows: 1
252-
:stub-columns: 1
253-
254-
* - Connection Option
255-
- Description
256-
257-
* - :manual:`authMechanism </reference/connection-string/#mongodb-urioption-urioption.authmechanism>`
258-
- | **Data Type**: {+string-data-type+}
259-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'authMechanism' => 'MONGODB-X509' ];``
260-
| **Connection URI Example**: ``authMechanism=MONGODB-X509``
261-
262-
* - :manual:`authMechanismProperties </reference/connection-string/#mongodb-urioption-urioption.authmechanismproperties>`
263-
- | **Data Type**: {+string-data-type+}
264-
| **MongoDB\\Client Example**:
265-
| ``$uriOptions = [ 'authMechanismProperties' => 'AWS_SESSION_TOKEN:12345' ];``
266-
|
267-
| **Connection URI Example**: ``authMechanismProperties=AWS_SESSION_TOKEN:12345``
268-
269-
* - :manual:`authSource </reference/connection-string/#mongodb-urioption-urioption.authsource>`
270-
- | **Data Type**: {+string-data-type+}
271-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'authSource' => 'admin' ];``
272-
| **Connection URI Example**: ``authSource=admin``
243+
To learn about the authentication options available in the {+driver-short+}, see
244+
:ref:`Authentication Mechanisms. <php-auth>`
273245

274246
Server Selection and Discovery Options
275247
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -282,29 +254,29 @@ Server Selection and Discovery Options
282254
* - Connection Option
283255
- Description
284256

285-
* - :manual:`localThresholdMS </reference/connection-string/#mongodb-urioption-urioption.localthresholdms>`
257+
* - :manual:`localThresholdMS </reference/connection-string-options/#mongodb-urioption-urioption.localthresholdms>`
286258
- | **Data Type**: {+int-data-type+}
287-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'localThresholdMS' => 20 ];``
259+
| **MongoDB\\Client Example**: ``$uriOptions = ['localThresholdMS' => 20];``
288260
| **Connection URI Example**: ``localThresholdMS=20``
289261

290-
* - :manual:`serverSelectionTimeoutMS </reference/connection-string/#mongodb-urioption-urioption.serverselectiontimeoutms>`
262+
* - :manual:`serverSelectionTimeoutMS </reference/connection-string-options/#mongodb-urioption-urioption.serverselectiontimeoutms>`
291263
- | **Data Type**: {+int-data-type+}
292-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'serverSelectionTimeoutMS' => 40000 ];``
264+
| **MongoDB\\Client Example**: ``$uriOptions = ['serverSelectionTimeoutMS' => 5000];``
293265
| **Connection URI Example**: ``serverSelectionTimeoutMS=40000``
294266

295-
* - :manual:`serverSelectionTryOnce </reference/connection-string/#mongodb-urioption-urioption.serverselectiontryonce>`
267+
* - :manual:`serverSelectionTryOnce </reference/connection-string-options/#mongodb-urioption-urioption.serverselectiontryonce>`
296268
- | **Data Type**: {+bool-data-type+}
297-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'serverSelectionTryOnce' => false ];``
269+
| **MongoDB\\Client Example**: ``$uriOptions = ['serverSelectionTryOnce' => false];``
298270
| **Connection URI Example**: ``serverSelectionTryOnce=false``
299271

300-
* - :manual:`heartbeatFrequencyMS </reference/connection-string/#mongodb-urioption-urioption.heartbeatfrequencyms>`
272+
* - :manual:`heartbeatFrequencyMS </reference/connection-string-options/#mongodb-urioption-urioption.heartbeatfrequencyms>`
301273
- | **Data Type**: {+int-data-type+}
302-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'heartbeatFrequencyMS' => 50000 ];``
274+
| **MongoDB\\Client Example**: ``$uriOptions = ['heartbeatFrequencyMS' => 50000];``
303275
| **Connection URI Example**: ``heartbeatFrequencyMS=50000``
304276

305-
* - :manual:`socketCheckIntervalMS </reference/connection-string/#mongodb-urioption-urioption.socketcheckintervalms>`
277+
* - :manual:`socketCheckIntervalMS </reference/connection-string-options/#mongodb-urioption-urioption.socketcheckintervalms>`
306278
- | **Data Type**: {+int-data-type+}
307-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'socketCheckIntervalMS' => 4000 ];``
279+
| **MongoDB\\Client Example**: ``$uriOptions = ['socketCheckIntervalMS' => 4000];``
308280
| **Connection URI Example**: ``socketCheckIntervalMS=4000``
309281

310282
Miscellaneous Configuration
@@ -317,29 +289,29 @@ Miscellaneous Configuration
317289
* - Connection Option
318290
- Description
319291

320-
* - :manual:`appName </reference/connection-string/#mongodb-urioption-urioption.appname>`
292+
* - :manual:`appName </reference/connection-string-options/#mongodb-urioption-urioption.appname>`
321293
- | **Data Type**: {+string-data-type+}
322-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'appName' => 'myApp' ];``
294+
| **MongoDB\\Client Example**: ``$uriOptions = ['appName' => 'myApp'];``
323295
| **Connection URI Example**: ``appName=myApp``
324296

325-
* - :manual:`retryReads </reference/connection-string/#mongodb-urioption-urioption.retryreads>`
297+
* - :manual:`retryReads </reference/connection-string-options/#mongodb-urioption-urioption.retryreads>`
326298
- | **Data Type**: {+bool-data-type+}
327-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'retryReads' => false ];``
299+
| **MongoDB\\Client Example**: ``$uriOptions = ['retryReads' => false];``
328300
| **Connection URI Example**: ``retryReads=false``
329301

330-
* - :manual:`retryWrites </reference/connection-string/#mongodb-urioption-urioption.retrywrites>`
302+
* - :manual:`retryWrites </reference/connection-string-options/#mongodb-urioption-urioption.retrywrites>`
331303
- | **Data Type**: {+bool-data-type+}
332-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'retryWrites' => false ];``
304+
| **MongoDB\\Client Example**: ``$uriOptions = ['retryWrites' => false];``
333305
| **Connection URI Example**: ``retryWrites=false``
334306

335-
* - :manual:`loadBalanced </reference/connection-string/#mongodb-urioption-urioption.loadbalanced>`
307+
* - :manual:`loadBalanced </reference/connection-string-options/#mongodb-urioption-urioption.loadbalanced>`
336308
- | **Data Type**: {+bool-data-type+}
337-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'loadBalanced' => true ];``
309+
| **MongoDB\\Client Example**: ``$uriOptions = ['loadBalanced' => true];``
338310
| **Connection URI Example**: ``loadBalanced=true``
339311

340-
* - :manual:`srvMaxHosts </reference/connection-string/#mongodb-urioption-urioption.srvmaxhosts>`
312+
* - :manual:`srvMaxHosts </reference/connection-string-options/#mongodb-urioption-urioption.srvmaxhosts>`
341313
- | **Data Type**: {+int-data-type+}
342-
| **MongoDB\\Client Example**: ``$uriOptions = [ 'srvMaxHosts' => 5 ];``
314+
| **MongoDB\\Client Example**: ``$uriOptions = ['srvMaxHosts' => 5];``
343315
| **Connection URI Example**: ``srvMaxHosts=5``
344316

345317
API Documentation

source/includes/connect/connection-options.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
$uri = "mongodb://<hostname>:<port>/";
1212

1313
// Set the connection options
14+
// Replace the placeholder with the actual path to the certificate key file
1415
$uriOptions = [
1516
'tls' => true,
1617
'tlsCertificateKeyFile' => '/path/to/file.pem'

0 commit comments

Comments
 (0)