{"record":{"id":"d07f149b3fb35fd9","repo":"apache/seatunnel","slug":"unsupported-operation-d07f14","errorCode":"UNSUPPORTED_OPERATION","errorMessage":"Bson format doesn't support non-string as key type of map. The type is: ${typeSummary}","messagePattern":"Bson format doesn't support non-string as key type of map\\. The type is: (.+?)","errorType":"error_code","errorClass":"MongodbConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/BsonToRowDataConverters.java","lineNumber":311,"sourceCode":"                                    + bsonValue\n                                    + \"' of type \"\n                                    + bsonValue.getBsonType());\n                }\n\n                List<BsonValue> in = bsonValue.asArray();\n                Object arr = Array.newInstance(type.getElementType().getTypeClass(), in.size());\n                for (int i = 0; i < in.size(); i++) {\n                    Array.set(arr, i, elementConverter.apply(in.get(i)));\n                }\n                return arr;\n            }\n        };\n    }\n\n    private static SerializableFunction<BsonValue, Object> createMapConverter(\n            String typeSummary, SeaTunnelDataType<?> keyType, SeaTunnelDataType<?> valueType) {\n        if (!keyType.getSqlType().equals(SqlType.STRING)) {\n            throw new MongodbConnectorException(\n                    UNSUPPORTED_OPERATION,\n                    \"Bson format doesn't support non-string as key type of map. The type is: \"\n                            + typeSummary);\n        }\n        SerializableFunction<BsonValue, Object> valueConverter =\n                createNullSafeInternalConverter(valueType);\n\n        return new SerializableFunction<BsonValue, Object>() {\n            private static final long serialVersionUID = 1L;\n\n            @Override\n            public Object apply(BsonValue bsonValue) {\n                if (!bsonValue.isDocument()) {\n                    throw new MongodbConnectorException(\n                            ILLEGAL_ARGUMENT,\n                            \"Unable to convert to rowType from unexpected value '\"\n                                    + bsonValue\n                                    + \"' of type \"","sourceCodeStart":293,"sourceCodeEnd":329,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/BsonToRowDataConverters.java#L293-L329","documentation":"createMapConverter validates that the MAP key type is STRING before building the converter. BSON object keys are always strings, so a MapType with a non-string key (INT, BIGINT, etc.) cannot round-trip through BSON, and the converter construction fails with MongodbConnectorException(UNSUPPORTED_OPERATION).","triggerScenarios":"Declaring a MAP<INT, V>, MAP<BIGINT, V>, or any non-STRING key type in the SeaTunnel schema for a MongoDB source; createInternalConverter -> createMapConverter raises at converter-build time.","commonSituations":"Reusing a schema from another connector (e.g. JDBC) where integer-keyed maps are fine; auto-generated schemas mapping Mongo fields to MAP with inferred non-string keys.","solutions":["Change the map key type to STRING in the schema definition.","Use a ROW or ARRAY<ROW<k,v>> structure to represent non-string-keyed data.","Store the map with string keys in MongoDB (e.g. keys as strings) and convert keys downstream.","If you own the code, extend createMapConverter to coerce numeric keys to strings during deserialization."],"exampleFix":"// before\nscores = MAP<INT, DOUBLE>\n// after\nscores = MAP<STRING, DOUBLE>","handlingStrategy":"validation","validationCode":"// Validate map key type before building the schema\nif (mapType.getKeyType().getSqlType() != SqlType.STRING) {\n    throw new IllegalArgumentException(\n        \"MongoDB connector requires MAP keys to be STRING, got: \" + mapType.getKeyType());\n}","typeGuard":null,"tryCatchPattern":"try {\n    buildSchema(options);\n} catch (MongodbConnectorException e) {\n    if (e.getMessage().contains(\"non-string as key type of map\")) {\n        // switch the map key type to STRING or restructure as ARRAY<ROW<k,v>>\n    } else { throw e; }\n}","preventionTips":["Always declare MAP<STRING, V> for MongoDB sources","Model non-string-keyed data as ROW or ARRAY<ROW<k,v>> instead of MAP","Remember BSON object keys are always strings; match your schema to that constraint"],"tags":["mongodb","sea-tunnel","serde","map-type","bson"],"backgroundTag":"unsupported-operation","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"}