@@ -114,6 +114,10 @@ It is also possible to require using the shared library by passing
114114``crypt_shared_lib_required: true`` option when creating a client. In this case,
115115an error will be raised if the shared library cannot be loaded.
116116
117+ .. note::
118+ All ``Mongo::Client`` objects in the same process should use the same setting
119+ ``:crypt_shared_lib_path``, as it is an error to load more that one crypt_shared dynamic library simultaneously in a single operating system process.
120+
117121mongocryptd
118122~~~~~~~~~~~
119123
@@ -166,6 +170,20 @@ in order to perform automatic encryption.
166170
167171 Automatic encryption requires the authenticated user to have the listCollections privilege action.
168172
173+ .. note::
174+
175+ When using Automatic Encryption, and a ``Mongo::Client`` instance that is configured
176+ with ``:auto_encryption_options`` has a limited connection pool size
177+ (i.e a non-zero ``:max_pool_size``, which is the default setting), a separate
178+ internal ``Mongo::Client`` instance is created if any of the following are true:
179+
180+ - ``auto_encryption_options[:key_vault_client]`` is not passed.
181+ - ``auto_encryption_options[:bypass_automatic_encryption]`` is not passed or false.
182+
183+ If an internal ``Mongo::Client`` instance is created, it is configured with
184+ the same options as the parent client except ``:min_pool_size`` is set to 0
185+ and ``:auto_encryption_options`` is omitted.
186+
169187.. code-block:: ruby
170188
171189 require 'mongo'
@@ -249,7 +267,7 @@ in order to perform automatic encryption.
249267 ['localhost:27017'],
250268 database: 'encryption_db',
251269 )
252- client_no_encryption. ['encryption_coll'].find.first['encrypted_field']
270+ client_no_encryption['encryption_coll'].find.first['encrypted_field']
253271 # => <BSON::Binary... type=ciphertext...>
254272
255273The example above demonstrates using automatic encryption with a local master key.
@@ -401,7 +419,7 @@ Below is an example of using automatic queryable encryption using the Ruby drive
401419
402420 # The key vault client is a Mongo::Client instance
403421 # that will be used to store your data keys.
404- key_vault_client = Mongo::Client.new([' localhost:27017'] )
422+ key_vault_client = Mongo::Client.new('mongodb:// localhost:27017,localhost:27018' )
405423
406424 # Use an instance of Mongo::ClientEncryption to create a new data key
407425 client_encryption = Mongo::ClientEncryption.new(
@@ -435,7 +453,7 @@ Below is an example of using automatic queryable encryption using the Ruby drive
435453
436454 # Configure the client for automatic encryption
437455 client = Mongo::Client.new(
438- [' localhost:27017'] ,
456+ 'mongodb:// localhost:27017,localhost:27018' ,
439457 auto_encryption_options: {
440458 key_vault_namespace: 'encryption.__keyVault',
441459 kms_providers: kms_providers,
@@ -496,7 +514,7 @@ Below is an example of explicit queryable encryption.
496514
497515 # The key vault client is a Mongo::Client instance
498516 # that will be used to store your data keys.
499- key_vault_client = Mongo::Client.new([' localhost:27017'] )
517+ key_vault_client = Mongo::Client.new('mongodb:// localhost:27017,localhost:27018' )
500518
501519 # Use an instance of Mongo::ClientEncryption to create a new data key
502520 client_encryption = Mongo::ClientEncryption.new(
@@ -511,27 +529,39 @@ Below is an example of explicit queryable encryption.
511529 ##########################################
512530 # Step 3: Create an encrypted collection #
513531 ##########################################
514-
515- # Create the client you will use to read and write the data to MongoDB
516- client = Mongo::Client.new(['localhost:27017'], database: 'encryption_db')
517-
518532 encrypted_fields = {
519533 fields: [
520534 {
521535 path: 'encrypted_field',
522536 bsonType: 'string',
523537 keyId: data_key_id,
524538 queries: {
525- queryType: 'equality'
539+ queryType: 'equality',
540+ contention: 0
526541 }
527542 }
528543 ]
529544 }
530545
546+ # Create the client you will use to read and write the data to MongoDB
547+ # Please note that to insert or query with an "Indexed" encrypted payload,
548+ # you should use a ``Mongo::Client`` that is configured with ``:auto_encryption_options``.
549+ # ``auto_encryption_options[:bypass_query_analysis]`` may be true.
550+ # ``auto_encryption_options[:bypass_auto_encryption]`` must be not set or false.
551+ client = Mongo::Client.new(
552+ ['localhost:27017'],
553+ auto_encryption_options: {
554+ key_vault_namespace: 'encryption.__keyVault',
555+ kms_providers: kms_providers,
556+ bypass_query_analysis: true,
557+ },
558+ database: 'encryption_db',
559+ )
560+
531561 # Make sure there is no data in the collection.
532- client['encryption_coll'].drop(encrypted_field : encrypted_fields)
562+ client['encryption_coll'].drop(encrypted_fields : encrypted_fields)
533563 # Create encrypted collection explicitly.
534- collection = client['encryption_coll'].create(encrypted_fields: encrypted_fields)
564+ client['encryption_coll'].create(encrypted_fields: encrypted_fields)
535565
536566 #####################################################
537567 # Step 4: Encrypt a string with explicit encryption #
@@ -545,24 +575,27 @@ Below is an example of explicit queryable encryption.
545575 'sensitive data',
546576 {
547577 key_id: data_key_id,
548- algorithm: "Indexed"
578+ algorithm: "Indexed",
579+ contention_factor: 0
549580 }
550581 )
551582
552583 # Insert the encrypted value into the collection
553- collection .insert_one(encrypted_field: insert_payload)
584+ client['encryption_coll'] .insert_one(encrypted_field: insert_payload)
554585
555586 # Use the client to read the encrypted value from the database, then
556- # use the ClientEncryption object to decrypt it
587+ # use the ClientEncryption object to decrypt it.
557588 find_payload = client_encryption.encrypt(
558589 'sensitive data',
559590 {
560591 key_id: data_key_id,
561592 algorithm: "Indexed",
593+ contention_factor: 0,
562594 query_type: "equality"
563595 }
564596 )
565- find_result = collection.find(encrypted_field: find_payload).first['encrypted_field']
597+
598+ find_result = client['encryption_coll'].find(encrypted_field: find_payload).first['encrypted_field']
566599 # => 'sensitive data'
567600
568601
0 commit comments