New in version 4.2.
ClientEncryptionobject for the current database collection. The
ClientEncryptionobject supports explicit (manual) encryption and decryption of field values for Client-Side field level encryption.
ClientEncryptionobject for current database connection.
getClientEncryption() has the following syntax:
ClientEncryption object to access the following
explicit encryption methods:
mongosh client-side field level encryption methods
require a database connection with client-side field level encryption
enabled. If the current database connection was not initiated with
client-side field level encryption enabled, either:
Mongo()constructor from the
mongoshto establish a connection with the required client-side field level encryption options. The
Mongo()method supports the following Key Management Service (KMS) providers for Customer Master Key (CMK) management:
getKeyVault() method automatically creates a
unique index on the
with a partial index filter for only
creates this index in the key vault collection. This prevents any two
data encryption keys in the same key vault from having the same key
alternative name and therefore avoids ambiguity around which data
encryption key is appropriate for encryption/decryption.
Do not drop the unique index created by
Client-Side Field Level Encryption operations depend on
server-enforced uniqueness of
keyAltNames. Removing the index
may lead to unexpected or unpredictable behavior.
The following example uses a locally managed KMS for the client-side field level encryption configuration.
Mongo() constructor with the client-side field level
encryption options configured to create a database connection. Replace
mongodb://myMongo.example.net URI with the connection
string URI of the target cluster.
encryptedClient = Mongo( "mongodb://myMongo.example.net:27017/?replSetName=myMongo", autoEncryptionOpts )
getClientEncryption() method to
retrieve the client encryption object:
clientEncryption = encryptedClient.getClientEncryption()
For complete documentation on initiating MongoDB connections with
client-side field level encryption enabled, see