apache/seatunnel · error · CatalogException

Failed to check database existence: ${databaseName}

Error message

Failed to check database existence: ${databaseName}

What it means

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.

Source

Thrown at seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/catalog/MongodbCatalog.java:79

        }
    }

    @Override
    public String name() {
        return catalogName;
    }

    @Override
    public String getDefaultDatabase() throws CatalogException {
        return defaultDatabase;
    }

    @Override
    public boolean databaseExists(String databaseName) throws CatalogException {
        try {
            return listDatabases().contains(databaseName);
        } catch (Exception e) {
            throw new CatalogException("Failed to check database existence: " + databaseName, e);
        }
    }

    @Override
    public List<String> listDatabases() throws CatalogException {
        try {
            List<String> dbs = new ArrayList<>();
            for (String name : mongoClient.listDatabaseNames()) {
                dbs.add(name);
            }
            return dbs;
        } catch (Exception e) {
            throw new CatalogException("Failed to list databases", e);
        }
    }

    @Override
    public List<String> listTables(String databaseName)

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Verify the MongoDB instance is reachable (ping/openssl check on host:port) and the URI in the catalog config is correct.
  2. Grant the catalog user the listDatabases privilege (cluster scope) or use a user with sufficient roles.
  3. Check authSource and credentials; test the same URI with mongosh.
  4. Inspect the wrapped cause ('Caused by') for the concrete driver error (timeout, auth, command not authorized).

Example fix

// before
user = { role: 'readWrite', db: 'mydb' } // cannot listDatabases
// after
user = { role: 'readWriteAnyDatabase', db: 'admin' } // or explicitly grant { role: 'clusterMonitor' }
Defensive patterns

Strategy: try-catch

Validate before calling

// check reachability and auth before catalog calls
try (MongoClient c = MongoClients.create(baseUrl)) {
    c.listDatabaseNames().first(); // throws if unreachable/unauthorized
}

Try / catch

try { exists = catalog.databaseExists(db); } catch (CatalogException e) { log.error("databaseExists failed for {}: {}", db, e.getCause(), e); throw e; }

Prevention

When it happens

Trigger: Calling databaseExists (directly or via listTables/createTable) when the MongoDB server is unreachable, authentication fails, or the listDatabases command is rejected by the server.

Common situations: 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.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/e90fc657e7d65851. Report an issue: GitHub.