Module: Mongo::Collection::QueryableEncryption Private
- Included in:
- Mongo::Collection
- Defined in:
- lib/mongo/collection/queryable_encryption.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
This module contains methods for creating and dropping auxiliary collections for queryable encryption.
Instance Method Summary collapse
-
#maybe_create_qe_collections(encrypted_fields, client, session) ⇒ Result
private
Creates auxiliary collections and indices for queryable encryption if necessary.
-
#maybe_drop_emm_collections(encrypted_fields, client, session) ⇒ Result
private
Drops auxiliary collections and indices for queryable encryption if necessary.
Instance Method Details
#maybe_create_qe_collections(encrypted_fields, client, session) ⇒ Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates auxiliary collections and indices for queryable encryption if necessary.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/mongo/collection/queryable_encryption.rb', line 34 def maybe_create_qe_collections(encrypted_fields, client, session) encrypted_fields = if encrypted_fields encrypted_fields elsif encrypted_fields_map encrypted_fields_map[namespace] || {} else {} end if encrypted_fields.empty? return yield end emm_collections(encrypted_fields).each do |coll| context = Operation::Context.new(client: client, session: session) Operation::Create.new( selector: { create: coll, clusteredIndex: { key: { _id: 1 }, unique: true } }, db_name: database.name, ).execute(next_primary(nil, session), context: context) 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
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Drops auxiliary collections and indices for queryable encryption if necessary.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/mongo/collection/queryable_encryption.rb', line 74 def maybe_drop_emm_collections(encrypted_fields, client, session) encrypted_fields = if encrypted_fields encrypted_fields elsif encrypted_fields_map if encrypted_fields_map[namespace] encrypted_fields_map[namespace] else database.list_collections(filter: { name: name }) .first &.fetch(:options, {}) &.fetch(:encryptedFields, {}) || {} end else {} end if encrypted_fields.empty? return yield end 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 |