{"record":{"id":"54398fa0e4fd788e","repo":"Automattic/mongoose","slug":"listdatabases-not-implemented-by-driver","errorCode":null,"errorMessage":"listDatabases() not implemented by driver","messagePattern":"listDatabases\\(\\) not implemented by driver","errorType":"exception","errorClass":"MongooseError","httpStatus":null,"severity":"error","filePath":"lib/connection.js","lineNumber":919,"sourceCode":"};\n\n/**\n * Helper for MongoDB Node driver's `listDatabases()`.\n * Returns an object with a `databases` property that contains an\n * array of database objects.\n *\n * #### Example:\n *     const { databases } = await mongoose.connection.listDatabases();\n *     databases; // [{ name: 'mongoose_test', sizeOnDisk: 0, empty: false }]\n *\n * @method listCollections\n * @return {Promise<Array<{ databases: { name: string } }>>}\n * @api public\n */\n\nConnection.prototype.listDatabases = async function listDatabases() {\n  // Implemented in `lib/drivers/node-mongodb-native/connection.js`\n  throw new MongooseError('listDatabases() not implemented by driver');\n};\n\n/**\n * Helper for `dropDatabase()`. Deletes the given database, including all\n * collections, documents, and indexes.\n *\n * #### Example:\n *\n *     const conn = mongoose.createConnection('mongodb://127.0.0.1:27017/mydb');\n *     // Deletes the entire 'mydb' database\n *     await conn.dropDatabase();\n *\n * @method dropDatabase\n * @return {Promise}\n * @api public\n */\n\nConnection.prototype.dropDatabase = async function dropDatabase() {","sourceCodeStart":901,"sourceCodeEnd":937,"githubUrl":"https://github.com/Automattic/mongoose/blob/49cdab01366679723b487ecb754b38570f783289/lib/connection.js#L901-L937","documentation":"The base Connection class only declares listDatabases(); the real implementation lives in the bundled node-mongodb-native driver (lib/drivers/node-mongodb-native/connection.js:222, which delegates to this.db.admin().listDatabases()). Seeing this error means the connection object is not backed by the native driver — a custom Connection subclass or test double that never overrode the method.","triggerScenarios":"Calling conn.listDatabases() on a custom Connection subclass, mock, or bare base Connection instance whose class does not override listDatabases().","commonSituations":"Writing unit-test fakes/stubs for Connection; building alternate driver adapters; rarely, instantiating the base Connection directly instead of using mongoose.createConnection().","solutions":["Use a standard connection: const conn = await mongoose.createConnection(uri).asPromise()","Bypass the Mongoose sugar and call the driver directly: const { databases } = await conn.db.admin().listDatabases()","If you maintain a custom connection class, implement listDatabases() on it"],"exampleFix":"// before\nconst conn = new CustomConnection(); // subclass lacking listDatabases\nawait conn.listDatabases(); // throws\n\n// after\nconst conn = await mongoose.createConnection(uri).asPromise();\nconst { databases } = await conn.listDatabases();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let databases;\ntry {\n  ({ databases } = await conn.listDatabases());\n} catch (err) {\n  if (/not implemented by driver/.test(err.message)) {\n    ({ databases } = await conn.db.admin().listDatabases());\n  } else {\n    throw err;\n  }\n}","preventionTips":["Create connections only through mongoose.connect()/mongoose.createConnection()","For custom driver classes, implement every documented Connection method","When unsure a custom connection supports the sugar, call the driver directly: conn.db.admin().listDatabases()"],"tags":["driver","listdatabases","abstract-method"],"backgroundTag":"driver-method-unimplemented","analyzedSha":"49cdab01366679723b487ecb754b38570f783289","analyzedAt":"2026-08-21T22:54:00.882Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}