{"record":{"id":"db36125a395b6fa5","repo":"apache/seatunnel","slug":"failed-to-create-collection-tablepath-getfullna","errorCode":null,"errorMessage":"Failed to create collection: ${tablePath.getFullName()}","messagePattern":"Failed to create collection: (.+?)","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":139,"sourceCode":"            throws CatalogException, TableNotExistException {\n        throw CommonError.unsupportedOperation(name(), \"get table with tablePath \");\n    }\n\n    @Override\n    public void createTable(TablePath tablePath, CatalogTable table, boolean ignoreIfExists)\n            throws TableAlreadyExistException, DatabaseNotExistException, CatalogException {\n        if (!databaseExists(tablePath.getDatabaseName())) {\n            throw new DatabaseNotExistException(name(), tablePath.getDatabaseName());\n        }\n        if (tableExists(tablePath)) {\n            if (ignoreIfExists) return;\n            throw new TableAlreadyExistException(name(), tablePath);\n        }\n        try {\n            MongoDatabase db = mongoClient.getDatabase(tablePath.getDatabaseName());\n            db.createCollection(tablePath.getTableName());\n        } catch (Exception e) {\n            throw new CatalogException(\n                    \"Failed to create collection: \" + tablePath.getFullName(), e);\n        }\n    }\n\n    @Override\n    public void dropTable(TablePath tablePath, boolean ignoreIfNotExists)\n            throws TableNotExistException, CatalogException {\n        if (!tableExists(tablePath)) {\n            if (ignoreIfNotExists) return;\n            throw new TableNotExistException(name(), tablePath);\n        }\n        try {\n            MongoDatabase db = mongoClient.getDatabase(tablePath.getDatabaseName());\n            db.getCollection(tablePath.getTableName()).drop();\n        } catch (Exception e) {\n            throw new CatalogException(\"Failed to drop collection: \" + tablePath.getFullName(), e);\n        }\n    }","sourceCodeStart":121,"sourceCodeEnd":157,"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#L121-L157","documentation":"After the existence checks pass, createTable calls db.createCollection(...); any driver/server failure is wrapped in a CatalogException \"Failed to create collection: <fullName>\". The wrapped cause carries the actual MongoDB error.","triggerScenarios":"Collection created by a concurrent writer between the tableExists check and createCollection (race), invalid collection name (e.g., contains null char or exceeds length limits), insufficient createCollection privileges, or connection loss.","commonSituations":"Concurrent jobs racing to create the same collection, restricted user lacking createCollection action, collection names with forbidden characters derived from table paths, server hitting namespace limits.","solutions":["Inspect e.getCause() for the Mongo error code (e.g., NamespaceExists means a race with another creator).","Treat Mongo error code 48 (NamespaceExists) as benign if ignoreIfExists semantics are desired — retry with existence check.","Sanitize the table name to meet MongoDB collection naming rules.","Grant the user createCollection privilege on the database.","Serialize creation (single writer) or use createCollection with ignore-duplicate handling."],"exampleFix":"// before\ndb.createCollection(tableName);\n// after\ntry {\n    db.createCollection(tableName);\n} catch (MongoCommandException e) {\n    if (e.getErrorCode() != 48) throw e; // 48 = NamespaceExists\n}","handlingStrategy":"try-catch","validationCode":"// validate name against MongoDB rules\nif (tableName.contains(\"\\u0000\") || tableName.length() > 255) {\n    throw new IllegalArgumentException(\"bad collection name\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    catalog.createTable(tablePath, table, true);\n} catch (CatalogException e) {\n    if (e.getCause() instanceof MongoCommandException\n        && ((MongoCommandException) e.getCause()).getErrorCode() == 48) {\n        // namespace exists: benign race\n    } else { throw e; }\n}","preventionTips":["Sanitize collection names (no null chars, <=255 bytes)","Grant createCollection privilege","Handle error code 48 as already-exists","Serialize collection creation across workers"],"tags":["mongodb","catalog","create-collection"],"backgroundTag":"database-write-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"}