Module: Mongo::Collection::QueryableEncryption Private
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | lib/mongo/collection/queryable_encryption.rb |
Overview
This module contains methods for creating and dropping auxiliary collections for queryable encryption.
Constant Summary
-
QE2_MIN_WIRE_VERSION =
The minimum wire version for QE2 support
21
Instance Method Summary
-
#maybe_create_qe_collections(encrypted_fields, client, session) ⇒ Result
Internal use only
Creates auxiliary collections and indices for queryable encryption if necessary.
-
#maybe_drop_emm_collections(encrypted_fields, client, session) ⇒ Result
Internal use only
Drops auxiliary collections and indices for queryable encryption if necessary.
-
#check_wire_version!(connection)
private
Internal use only
Creating encrypted collections is only supported on 7.0.0 and later (wire version 21+).
-
#create_operation_for(coll) ⇒ Operation::Create
private
Internal use only
Returns a new create operation for the given collection.
-
#emm_collections(encrypted_fields) ⇒ Array <String>
private
Internal use only
Checks if names for auxiliary collections are set and returns them, otherwise returns default names.
-
#encrypted_fields_for_drop_from_map ⇒ Hash | nil
private
Internal use only
Tries to return the encrypted fields from the
{encrypted_fields_map
} value, for the current namespace. -
#encrypted_fields_from(fields) ⇒ Hash
private
Internal use only
Tries to return the encrypted fields from the argument.
Instance Method Details
#check_wire_version!(connection) (private)
Creating encrypted collections is only supported on 7.0.0 and later (wire version 21+).
# File 'lib/mongo/collection/queryable_encryption.rb', line 109
def check_wire_version!(connection) return unless connection.description.max_wire_version < QE2_MIN_WIRE_VERSION raise Mongo::Error, 'Driver support of Queryable Encryption is incompatible with server. ' \ 'Upgrade server to use Queryable Encryption.' end
#create_operation_for(coll) ⇒ Operation::Create (private)
Returns a new create operation for the given collection.
#emm_collections(encrypted_fields) ⇒ Array
<String
> (private)
Checks if names for auxiliary collections are set and returns them, otherwise returns default names.
#encrypted_fields_for_drop_from_map ⇒ Hash
| nil
(private)
Tries to return the encrypted fields from the {encrypted_fields_map
} value, for the current namespace.
#encrypted_fields_from(fields) ⇒ Hash
(private)
Tries to return the encrypted fields from the argument. If the argument is nil, tries to find the encrypted fields from the encrypted_fields_map.
# File 'lib/mongo/collection/queryable_encryption.rb', line 124
def encrypted_fields_from(fields) fields || (encrypted_fields_map && encrypted_fields_map[namespace]) || {} end
#maybe_create_qe_collections(encrypted_fields, client, session) ⇒ Result
Creates auxiliary collections and indices for queryable encryption if necessary.
# File 'lib/mongo/collection/queryable_encryption.rb', line 35
def maybe_create_qe_collections(encrypted_fields, client, session) encrypted_fields = encrypted_fields_from(encrypted_fields) return yield if encrypted_fields.empty? server = next_primary(nil, session) context = Operation::Context.new(client: client, session: session) server.with_connection do |connection| check_wire_version!(connection) emm_collections(encrypted_fields).each do |coll| create_operation_for(coll) .execute_with_connection(connection, context: context) end end yield(encrypted_fields).tap do |result| indexes.create_one(__safeContent__: 1) if result end end
#maybe_drop_emm_collections(encrypted_fields, client, session) ⇒ Result
Drops auxiliary collections and indices for queryable encryption if necessary.
# File 'lib/mongo/collection/queryable_encryption.rb', line 62
def maybe_drop_emm_collections(encrypted_fields, client, session) encrypted_fields = if encrypted_fields encrypted_fields elsif encrypted_fields_map encrypted_fields_for_drop_from_map else {} end return yield if encrypted_fields.empty? emm_collections(encrypted_fields).each do |coll| context = Operation::Context.new(client: client, session: session) operation = Operation::Drop.new( selector: { drop: coll }, db_name: database.name, session: session ) do_drop(operation, session, context) end yield end