{"record":{"id":"d5e278c3502626e9","repo":"apache/seatunnel","slug":"failed-to-list-databases-d5e278","errorCode":null,"errorMessage":"Failed to list databases","messagePattern":"Failed to list databases","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":92,"sourceCode":"    @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)\n            throws CatalogException, DatabaseNotExistException {\n        if (!databaseExists(databaseName)) {\n            throw new DatabaseNotExistException(name(), databaseName);\n        }\n        try {\n            MongoDatabase db = mongoClient.getDatabase(databaseName);\n            return db.listCollectionNames().into(new ArrayList<>());\n        } catch (Exception e) {\n            throw new CatalogException(\"Failed to list tables for database: \" + databaseName, e);\n        }\n    }\n\n    @Override","sourceCodeStart":74,"sourceCodeEnd":110,"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#L74-L110","documentation":"MongodbCatalog.listDatabases() wraps any failure while iterating mongoClient.listDatabaseNames() into a CatalogException. This means the MongoDB server could not be contacted or the listDatabases command was rejected. The underlying cause is attached as the cause.","triggerScenarios":"Calling listDatabases() (directly or via databaseExists) when the MongoDB server is down, the host/port in the connection string is wrong, credentials are invalid, or the connected user lacks listDatabases privileges.","commonSituations":"Wrong mongodb:// connection URI in catalog options, MongoDB not yet started in Docker/dev, firewall or DNS failure, user missing clusterMonitor role on admin DB, replica set primary unavailable.","solutions":["Verify the catalog's mongodb connection URI and that the server is reachable (mongosh with the same URI).","Check credentials in the URI and that the user has the necessary privilege (clusterMonitor / listDatabases on admin).","Inspect the wrapped cause exception (getCause()) for the concrete driver error (timeout, auth, DNS).","If using a replica set, ensure the seed list includes reachable members and the client can find the primary.","Increase connectTimeout/socketTimeout options if the server is slow to respond."],"exampleFix":"// before\nList<String> dbs = catalog.listDatabases();\n// after\ntry {\n    List<String> dbs = catalog.listDatabases();\n} catch (CatalogException e) {\n    LOG.error(\"listDatabases failed: {}\", e.getCause() != null ? e.getCause().getMessage() : e.getMessage(), e);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// preflight connection check\ntry (MongoClient c = MongoClients.create(uri)) {\n    c.listDatabaseNames().first(); // throws if unreachable/unauthorized\n}","typeGuard":null,"tryCatchPattern":"try {\n    catalog.listDatabases();\n} catch (CatalogException e) {\n    // log e.getCause() (MongoTimeoutException / MongoSecurityException)\n}","preventionTips":["Validate the MongoDB URI with a client ping at startup","Grant clusterMonitor role for catalog metadata operations","Set explicit connectTimeout and serverSelectionTimeout","Keep a mongosh-based smoke test in CI"],"tags":["mongodb","catalog","connection"],"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"}