{"record":{"id":"1ad09b5161adbf8d","repo":"Automattic/mongoose","slug":"the-mongodb-driver-must-be-used-to-obtain-a-client","errorCode":null,"errorMessage":"The mongodb driver must be used to obtain a ClientEncryption object.","messagePattern":"The mongodb driver must be used to obtain a ClientEncryption object\\.","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/model.js","lineNumber":5098,"sourceCode":"  Object.setPrototypeOf(model.Query.prototype, Query.prototype);\n  model.Query.base = Query.base;\n  model.Query.prototype.constructor = Query;\n  model._applyQueryMiddleware();\n  applyQueryMethods(model, schema.query);\n\n  return model;\n};\n\n/**\n * If auto encryption is enabled, returns a ClientEncryption instance that is configured with the same settings that\n * Mongoose's underlying MongoClient is using.  If the client has not yet been configured, returns null.\n *\n * @returns {ClientEncryption | null}\n */\nModel.clientEncryption = function clientEncryption() {\n  const ClientEncryption = this.base.driver.get().ClientEncryption;\n  if (!ClientEncryption) {\n    throw new MongooseError('The mongodb driver must be used to obtain a ClientEncryption object.');\n  }\n\n  const client = this.collection?.conn?.client;\n\n  if (!client) return null;\n\n  const autoEncryptionOptions = client.options.autoEncryption;\n\n  if (!autoEncryptionOptions) return null;\n\n  const {\n    keyVaultNamespace,\n    keyVaultClient,\n    kmsProviders,\n    credentialProviders,\n    proxyOptions,\n    tlsOptions\n  } = autoEncryptionOptions;","sourceCodeStart":5080,"sourceCodeEnd":5116,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/model.js#L5080-L5116","documentation":"Error \"The mongodb driver must be used to obtain a ClientEncryption object.\" thrown in Automattic/mongoose.","triggerScenarios":"Thrown at lib/model.js:5098 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}