{"record":{"id":"e90fc657e7d65851","repo":"apache/seatunnel","slug":"failed-to-check-database-existence-databasename","errorCode":null,"errorMessage":"Failed to check database existence: ${databaseName}","messagePattern":"Failed to check database existence: (.+?)","errorType":"exception","errorClass":"CatalogException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/catalog/MongodbCatalog.java","lineNumber":79,"sourceCode":"        }\n    }\n\n    @Override\n    public String name() {\n        return catalogName;\n    }\n\n    @Override\n    public String getDefaultDatabase() throws CatalogException {\n        return defaultDatabase;\n    }\n\n    @Override\n    public boolean databaseExists(String databaseName) throws CatalogException {\n        try {\n            return listDatabases().contains(databaseName);\n        } catch (Exception e) {\n            throw new CatalogException(\"Failed to check database existence: \" + databaseName, e);\n        }\n    }\n\n    @Override\n    public List<String> listDatabases() throws CatalogException {\n        try {\n            List<String> dbs = new ArrayList<>();\n            for (String name : mongoClient.listDatabaseNames()) {\n                dbs.add(name);\n            }\n            return dbs;\n        } catch (Exception e) {\n            throw new CatalogException(\"Failed to list databases\", e);\n        }\n    }\n\n    @Override\n    public List<String> listTables(String databaseName)","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/catalog/MongodbCatalog.java#L61-L97","documentation":"MongodbCatalog.databaseExists checks membership in listDatabases() and wraps any exception in a CatalogException 'Failed to check database existence: <databaseName>'. It is called by listTables and createTable, so a connectivity or authorization failure during database listing surfaces here.","triggerScenarios":"Calling databaseExists (directly or via listTables/createTable) when the MongoDB server is unreachable, authentication fails, or the listDatabases command is rejected by the server.","commonSituations":"Wrong credentials or missing listDatabases privilege for the user; MongoDB down or wrong host/port in the URI; firewall or TLS issues; using a user scoped to a single database without cluster-wide list permission.","solutions":["Verify the MongoDB instance is reachable (ping/openssl check on host:port) and the URI in the catalog config is correct.","Grant the catalog user the listDatabases privilege (cluster scope) or use a user with sufficient roles.","Check authSource and credentials; test the same URI with mongosh.","Inspect the wrapped cause ('Caused by') for the concrete driver error (timeout, auth, command not authorized)."],"exampleFix":"// before\nuser = { role: 'readWrite', db: 'mydb' } // cannot listDatabases\n// after\nuser = { role: 'readWriteAnyDatabase', db: 'admin' } // or explicitly grant { role: 'clusterMonitor' }","handlingStrategy":"try-catch","validationCode":"// check reachability and auth before catalog calls\ntry (MongoClient c = MongoClients.create(baseUrl)) {\n    c.listDatabaseNames().first(); // throws if unreachable/unauthorized\n}","typeGuard":null,"tryCatchPattern":"try { exists = catalog.databaseExists(db); } catch (CatalogException e) { log.error(\"databaseExists failed for {}: {}\", db, e.getCause(), e); throw e; }","preventionTips":["Grant the catalog user listDatabases/clusterMonitor privileges","Verify host, port, authSource and credentials with mongosh","Always inspect the wrapped cause of CatalogException for the concrete driver error"],"tags":["mongodb","catalog","database-exists","connectivity"],"backgroundTag":"database-query-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}