apache/seatunnel · error · DatabaseNotExistException

Database ${databaseName} does not exist in catalog ${name()}

Error message

Database ${databaseName} does not exist in catalog ${name()}

What it means

listTables(databaseName) first checks databaseExists(databaseName); if the database is not present in the MongoDB server's database list, it throws DatabaseNotExistException naming the catalog and database. This is a pre-check failure, not a driver failure.

Source

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

    @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)
            throws CatalogException, DatabaseNotExistException {
        if (!databaseExists(databaseName)) {
            throw new DatabaseNotExistException(name(), databaseName);
        }
        try {
            MongoDatabase db = mongoClient.getDatabase(databaseName);
            return db.listCollectionNames().into(new ArrayList<>());
        } catch (Exception e) {
            throw new CatalogException("Failed to list tables for database: " + databaseName, e);
        }
    }

    @Override
    public boolean tableExists(TablePath tablePath) throws CatalogException {
        try {
            return listTables(tablePath.getDatabaseName()).contains(tablePath.getTableName());
        } catch (DatabaseNotExistException e) {
            return false;
        }
    }

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Confirm the database name spelling and casing exactly matches the server (show dbs / db.getMongo().getDBs()).
  2. Check that the connected user has privileges to see the database (listDatabases on admin).
  3. Create the database/collection first, or use a catalog option that creates it if missing.
  4. If privileges hide it, grant the user clusterMonitor role.

Example fix

// before
List<String> tables = catalog.listTables("MyDB");
// after
List<String> dbs = catalog.listDatabases();
if (dbs.contains("MyDB")) {
    List<String> tables = catalog.listTables("MyDB");
}
Defensive patterns

Strategy: validation

Validate before calling

if (!catalog.databaseExists(TablePath.of(db, "_"))) {
    throw new IllegalArgumentException("DB missing: " + db);
}

Try / catch

try {
    catalog.listTables(dbName);
} catch (DatabaseNotExistException e) {
    // create DB or fix name
}

Prevention

When it happens

Trigger: Calling listTables with a database name that does not exist on the server, or a name with a typo/different case, or when listDatabases fails internally making the database appear missing (insufficient privileges can hide databases).

Common situations: Typo in database name in the job config, MongoDB auth restricting visible databases so databaseExists returns false, case-sensitive name mismatch (MongoDB names are case-sensitive).

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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