@@ -29,7 +29,7 @@ to connect to; if no database name is specified, the client will use the
29
29
.. code-block:: ruby
30
30
31
31
Mongo::Client.new([ '127.0.0.1:27017' ], database: 'mydb')
32
-
32
+
33
33
# Or using the URI syntax:
34
34
Mongo::Client.new("mongodb://127.0.0.1:27017/mydb")
35
35
@@ -82,7 +82,7 @@ The database can be specified during ``Client`` construction:
82
82
83
83
# Using Ruby client options:
84
84
client = Mongo::Client.new(['localhost'], database: 'mydb')
85
-
85
+
86
86
# Using a MongoDB URI:
87
87
client = Mongo::Client.new('mongodb://localhost/mydb')
88
88
@@ -92,9 +92,9 @@ new ``Client`` instance configured with the specified database:
92
92
.. code-block:: ruby
93
93
94
94
client = Mongo::Client.new(['localhost'], database: 'mydb')
95
-
95
+
96
96
admin_client = client.use('admin')
97
-
97
+
98
98
# Issue an administrative command
99
99
admin_client.database.command(replSetGetConfig: 1).documents.first
100
100
@@ -125,7 +125,7 @@ To force all operations to be performed on the designated server, specify the
125
125
.. code-block:: ruby
126
126
127
127
Mongo::Client.new([ '1.2.3.4:27017' ], database: 'mydb', direct_connection: true)
128
-
128
+
129
129
# Or using the URI syntax:
130
130
Mongo::Client.new("mongodb://1.2.3.4:27017/mydb?directConnection=true")
131
131
@@ -153,7 +153,7 @@ connect to the replica set.
153
153
154
154
Mongo::Client.new([ '127.0.0.1:27017', '127.0.0.1:27018' ],
155
155
:database => 'mydb', replica_set: 'myapp')
156
-
156
+
157
157
# Or using the URI syntax:
158
158
Mongo::Client.new("mongodb://127.0.0.1:27017,127.0.0.1:27018/mydb?replicaSet=myapp")
159
159
@@ -186,7 +186,7 @@ spread the operation load accordingly.
186
186
.. code-block:: ruby
187
187
188
188
Mongo::Client.new([ '1.2.3.4:27017', '1.2.3.5:27017' ], :database => 'mydb')
189
-
189
+
190
190
Mongo::Client.new("mongodb://1.2.3.4:27017,1.2.3.5:27017/mydb")
191
191
192
192
@@ -270,7 +270,7 @@ Ruby Options
270
270
271
271
* - ``:auth_mech_properties``
272
272
- Provides additional authentication mechanism properties.
273
-
273
+
274
274
The keys in properties are interpreted case-insensitively.
275
275
When the client is created, keys are lowercased.
276
276
@@ -319,8 +319,8 @@ Ruby Options
319
319
- none
320
320
321
321
* - ``:compressors``
322
- - A list of potential compressors to use, in order of preference. The driver chooses the first
323
- compressor that is also supported by the server. Currently the driver only supports 'zlib' .
322
+ - A list of potential compressors to use, in order of preference.
323
+ Please see below for details on how the driver implements compression .
324
324
- ``Array<String>``
325
325
- none
326
326
@@ -436,11 +436,11 @@ Ruby Options
436
436
max_staleness: 5,
437
437
}
438
438
}
439
-
439
+
440
440
If tag sets are provided, they must be an array of hashes. A server
441
441
satisfies the read preference if its tags match any one hash in the
442
442
provided tag sets.
443
-
443
+
444
444
Each tag set must be a hash, and will be converted internally to
445
445
a ``BSON::Document`` instance prior to being used for server selection.
446
446
Hash keys can be strings or symbols. The keys are case sensitive.
@@ -480,12 +480,12 @@ Ruby Options
480
480
subscriber not receiving some of the SDAM events. The ``:sdam_proc``
481
481
option permits adding event subscribers on the client being constructed
482
482
before any SDAM events are published.
483
-
483
+
484
484
Pass a ``Proc`` which will be called with the ``Client`` as the argument
485
485
after the client's event subscription mechanism has been initialized
486
486
but before any of the servers are added to the client. Use this
487
487
``Proc`` to set up SDAM event subscribers on the client.
488
-
488
+
489
489
Note: the client is not fully constructed when the ``Proc`` provided in
490
490
``:sdam_proc is invoked, in particular the cluster is nil at this time.
491
491
``:sdam_proc`` procedure should limit itself to calling
@@ -696,6 +696,7 @@ URI options are explained in detail in the :manual:`Connection URI reference
696
696
</reference/connection-string/>`.
697
697
698
698
.. note::
699
+
699
700
Options that are set in **milliseconds** in the URI are
700
701
represented as a ``float`` in Ruby and the units are **seconds**.
701
702
@@ -1090,6 +1091,53 @@ file and both must be stored in the same file. Example usage:
1090
1091
URI option values must be properly URI escaped. This applies, for example, to
1091
1092
slashes in the paths.
1092
1093
1094
+
1095
+ .. _modifying-tls-context:
1096
+
1097
+ Modifying ``SSLContext``
1098
+ ------------------------
1099
+ It may be desirable to further configure TLS options in the driver, for example
1100
+ by enabling or disabling certain ciphers. Currently, the Ruby driver does not
1101
+ provide a way to do this when initializing a ``Mongo::Client``.
1102
+
1103
+ However, the Ruby driver provides a way to set global "TLS context hooks" --
1104
+ these are user-provided ``Proc``s that will be invoked before any TLS socket
1105
+ connection and can be used to modify the underlying ``OpenSSL::SSL::SSLContext``
1106
+ object used by the socket.
1107
+
1108
+ To set the TLS context hooks, add ``Proc``s to the ``Mongo.tls_context_hooks``
1109
+ array. This should be done before creating any Mongo::Client instances.
1110
+ For example, in a Rails application this code could be placed in an initializer.
1111
+
1112
+ .. code-block:: ruby
1113
+
1114
+ Mongo.tls_context_hooks.push(
1115
+ Proc.new { |context|
1116
+ context.ciphers = ["AES256-SHA"]
1117
+ }
1118
+ )
1119
+
1120
+ # Only the AES256-SHA cipher will be enabled from this point forward
1121
+
1122
+ Every ``Proc`` in ``Mongo.tls_context_hooks`` will be passed an
1123
+ ``OpenSSL::SSL::SSLContext`` object as its sole argument. These ``Proc``s will
1124
+ be executed sequentially during the creation of every ``Mongo::Socket::SSL`` object.
1125
+
1126
+ It is possible to assign the entire array of hooks calling ``Mongo.tls_context_hooks=``,
1127
+ but doing so will remove any previously assigned hooks. It is recommended to use
1128
+ the ``Array#push`` or ``Array#unshift`` methods to add new hooks.
1129
+
1130
+ It is also possible to remove hooks from ``Mongo.tls_context_hooks`` by storing
1131
+ a reference to the Procs somewhere else in the application, and then using
1132
+ ``Array#delete_if`` to remove the desired hooks.
1133
+
1134
+ .. warning::
1135
+
1136
+ TLS context hooks are global and will affect every instance of ``Mongo::Client``.
1137
+ Any library that allows applications to enable these hooks should expose methods to
1138
+ modify the hooks (which can be called by the application) rather than
1139
+ automatically enabling the hooks when the library is loaded.
1140
+
1093
1141
Further information on configuring MongoDB server for TLS is available in the
1094
1142
:manual:`MongoDB manual </tutorial/configure-ssl/>`.
1095
1143
@@ -1162,10 +1210,13 @@ The ``:ssl_ca_cert_string`` option supports specifying only one CA certificate.
1162
1210
CA certificate options. Doing so would elevate the intermediate certificates
1163
1211
to the status of root certificates, rather than verifying intermediate
1164
1212
certificates against the root certificates.
1165
-
1213
+
1166
1214
If intermediate certificates need to be used, specify them as part of the
1167
1215
client or server TLS certificate files.
1168
1216
1217
+
1218
+ .. _ocsp-verification:
1219
+
1169
1220
OCSP Verification
1170
1221
-----------------
1171
1222
@@ -1300,7 +1351,7 @@ Usage with Forking Servers
1300
1351
==========================
1301
1352
1302
1353
.. note::
1303
-
1354
+
1304
1355
Applications using Mongoid should follow `Mongoid's forking guidance
1305
1356
<https://docs.mongodb.com/mongoid/current/tutorials/mongoid-configuration/#usage-with-forking-servers>`_.
1306
1357
The guidance and sample code below is provided for applications using the
@@ -1316,7 +1367,7 @@ This is because:
1316
1367
2. File descriptors like network sockets are shared between parent and
1317
1368
child processes.
1318
1369
1319
- The driver attempts to detect client use from forked processes and
1370
+ The driver attempts to detect client use from forked processes and
1320
1371
reestablish network connections when such use is detected, alleviating
1321
1372
the issue of file descriptor sharing.
1322
1373
0 commit comments