Automattic/mongoose · error · MongooseError
The mongodb driver must be used to obtain a ClientEncryption
Error message
The mongodb driver must be used to obtain a ClientEncryption object.
What it means
Error "The mongodb driver must be used to obtain a ClientEncryption object." thrown in Automattic/mongoose.
Source
Thrown at lib/model.js:5098
Object.setPrototypeOf(model.Query.prototype, Query.prototype);
model.Query.base = Query.base;
model.Query.prototype.constructor = Query;
model._applyQueryMiddleware();
applyQueryMethods(model, schema.query);
return model;
};
/**
* If auto encryption is enabled, returns a ClientEncryption instance that is configured with the same settings that
* Mongoose's underlying MongoClient is using. If the client has not yet been configured, returns null.
*
* @returns {ClientEncryption | null}
*/
Model.clientEncryption = function clientEncryption() {
const ClientEncryption = this.base.driver.get().ClientEncryption;
if (!ClientEncryption) {
throw new MongooseError('The mongodb driver must be used to obtain a ClientEncryption object.');
}
const client = this.collection?.conn?.client;
if (!client) return null;
const autoEncryptionOptions = client.options.autoEncryption;
if (!autoEncryptionOptions) return null;
const {
keyVaultNamespace,
keyVaultClient,
kmsProviders,
credentialProviders,
proxyOptions,
tlsOptions
} = autoEncryptionOptions;View on GitHub (pinned to 49cdab0136)
When it happens
Trigger: Thrown at lib/model.js:5098 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of Automattic/mongoose@49cdab0136 (2026-08-21).
Data as JSON: /api/errors/1ad09b5161adbf8d.
Report an issue: GitHub.