new AutoEncrypter(client, options)
Create an AutoEncrypter
Note: Do not instantiate this class directly. Rather, supply the relevant options to a MongoClient
Note: Supplying options.schemaMap provides more security than relying on JSON Schemas obtained from the server.
It protects against a malicious server advertising a false JSON Schema, which could trick the client into sending unencrypted data that should be encrypted.
Schemas supplied in the schemaMap only apply to configuring automatic encryption for client side encryption.
Other validation rules in the JSON schema will not be enforced by the driver and will result in an error.
| Name | Type | Description |
|---|---|---|
client |
MongoClient |
The client autoEncryption is enabled on |
options |
AutoEncrypter~AutoEncryptionOptions |
optional
Optional settings |
Example
// Enabling autoEncryption via a MongoClient
const { MongoClient } = require('mongodb');
const client = new MongoClient(URL, {
autoEncryption: {
kmsProviders: {
aws: {
accessKeyId: AWS_ACCESS_KEY,
secretAccessKey: AWS_SECRET_KEY
}
}
}
});
await client.connect();
// From here on, the client will be encrypting / decrypting automatically
Members
-
innerlogLevelnumber
-
The level of severity of the log message
Value Level 0 Fatal Error 1 Error 2 Warning 3 Info 4 Trace
Type Definitions
-
AutoEncryptionExtraOptionsobject
-
Extra options related to the mongocryptd process
Properties:
Name Type Argument Default Description mongocryptdURIstring <optional>
A local process the driver communicates with to determine how to encrypt values in a command. Defaults to "mongodb://%2Fvar%2Fmongocryptd.sock" if domain sockets are available or "mongodb://localhost:27020" otherwise
mongocryptdBypassSpawnboolean <optional>
false If true, autoEncryption will not attempt to spawn a mongocryptd before connecting
mongocryptdSpawnPathstring <optional>
The path to the mongocryptd executable on the system
mongocryptdSpawnArgsArray.<string> <optional>
Command line arguments to use when auto-spawning a mongocryptd
-
AutoEncryptionOptionsObject
-
Configuration options for a automatic client encryption.
Properties:
Name Type Argument Description keyVaultClientMongoClient <optional>
A
MongoClientused to fetch keys from a key vaultkeyVaultNamespacestring <optional>
The namespace where keys are stored in the key vault
kmsProvidersKMSProviders <optional>
Configuration options that are used by specific KMS providers during key generation, encryption, and decryption.
schemaMapobject <optional>
A map of namespaces to a local JSON schema for encryption
bypassAutoEncryptionboolean <optional>
Allows the user to bypass auto encryption, maintaining implicit decryption
options.loggerAutoEncrypter~logger <optional>
An optional hook to catch logging messages from the underlying encryption engine
extraOptionsAutoEncrypter~AutoEncryptionExtraOptions <optional>
Extra options related to the mongocryptd process
-
logger(level, message)
-
A callback that is invoked with logging information from
the underlying C++ Bindings.Name Type Description levelAutoEncrypter~logLevel The level of logging.
messagestring The message to log