{"record":{"id":"2ead5f47e67cac5d","repo":"apache/seatunnel","slug":"failed-to-list-tables-for-database-databasename","errorCode":null,"errorMessage":"Failed to list tables for database: ${databaseName}","messagePattern":"Failed to list tables for database: (.+?)","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":106,"sourceCode":"                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\n    public boolean tableExists(TablePath tablePath) throws CatalogException {\n        try {\n            return listTables(tablePath.getDatabaseName()).contains(tablePath.getTableName());\n        } catch (DatabaseNotExistException e) {\n            return false;\n        }\n    }\n\n    @Override\n    public CatalogTable getTable(TablePath tablePath)\n            throws CatalogException, TableNotExistException {\n        throw CommonError.unsupportedOperation(name(), \"get table with tablePath \");\n    }\n","sourceCodeStart":88,"sourceCodeEnd":124,"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#L88-L124","documentation":"Thrown by MongodbCatalog.listTables when listing collection names via the Mongo driver fails after the database existence check passed; wraps the driver exception and names the database whose collections could not be listed.","triggerScenarios":"Calling listTables when the connection dropped after the existence check, the user lacks listCollections permission on that database, or a transient network/timeout error occurs during listing.","commonSituations":"User with read-only limited role missing listCollections action, network blip between existence check and listing, secondary read preference with an unavailable secondary.","solutions":["Check the user's privileges: it needs listCollections on the target database.","Inspect e.getCause() for the MongoDB driver error code to distinguish auth vs network.","Retry on transient network errors; the list is not destructive.","Verify replica set health / read preference configuration."],"exampleFix":"// before\nList<String> tables = catalog.listTables(dbName);\n// after\ntry {\n    List<String> tables = catalog.listTables(dbName);\n} catch (CatalogException e) {\n    if (e.getCause() instanceof MongoTimeoutException) {\n        tables = catalog.listTables(dbName); // retry once\n    } else { throw e; }\n}","handlingStrategy":"try-catch","validationCode":"// ensure privileges first\n// db.getSiblingDB(admin).runCommand({usersInfo: \"user\"}) shows roles","typeGuard":null,"tryCatchPattern":"try {\n    catalog.listTables(dbName);\n} catch (CatalogException e) {\n    Throwable c = e.getCause();\n    if (c instanceof MongoTimeoutException) { /* retry */ }\n}","preventionTips":["Grant listCollections privilege on target DBs","Retry idempotent metadata reads on transient errors","Monitor replica set health","Check e.getCause() before deciding to retry"],"tags":["mongodb","catalog","permissions"],"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-23T08:17:48.524Z"}