I also had the same problem. But my app runs in a Cloud Function (like AWS Lambda) and installing something is not possible.
Despite docs and forums said that Atlas support Auto Encrypt I couldn't make this work. So I tried Explicit Encryption that work's fine.
So you just need to specify bypassAutoEncryption
attribute:
const secureClient = new MongoClient(connectionString, {
useNewUrlParser: true,
useUnifiedTopology: true,
autoEncryption: {
bypassAutoEncryption: true, // explicit encryption
keyVaultNamespace,
kmsProviders,
// schemaMap: userSchema,
// extraOptions,
},
});
And encrypt data by yourself (what I find better - I have more control):
const randomEnc = {
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Random',
// keyId: [new Binary(Buffer.from(dataKey, 'base64'), 4)], // I also couldn't make this work
keyAltName: 'demo-data-key',
};
const writeResult = await secureClient
.db(db)
.collection(coll)
.insertOne({
name: 'Jon Doe',
ssn: await encryption.encrypt(241014209, randomEnc),
bloodType: await encryption.encrypt('AB+', randomEnc),
'key-id': 'demo-data-key',
medicalRecords: await encryption.encrypt([{ weight: 180, bloodPressure: '120/80' }], randomEnc),
insurance: {
policyNumber: await encryption.encrypt(123142, randomEnc),
provider: 'MaestCare',
},
});
Decryption will be automatic, you don't need to do anything.