apache/seatunnel · error · MongodbConnectorException
UNSUPPORTED_OPERATION
UNSUPPORTED_OPERATION
Error message
JSON format doesn't support non-string as key type of map. The type is: ${typeSummary} What it means
The MongoDB sink's JSON/BSON serialization layer rejects map types whose keys are not strings. BSON (and JSON) documents require field names to be strings, so any SeaTunnel MAP with a non-STRING key type (e.g. MAP<INT,STRING>) cannot be converted to a BSON document. The converter is built once per row type at sink initialization, so this fails fast when the converter is created.
Source
Thrown at seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/RowDataToBsonConverters.java:279
return new SerializableFunction<Object, BsonValue>() {
private static final long serialVersionUID = 1L;
@Override
public BsonValue apply(Object value) {
Object[] arrayData = (Object[]) value;
final List<BsonValue> bsonValues = new ArrayList<>();
for (Object element : arrayData) {
bsonValues.add(elementConverter.apply(element));
}
return new BsonArray(bsonValues);
}
};
}
private static SerializableFunction<Object, BsonValue> createMapConverter(
String typeSummary, SeaTunnelDataType<?> keyType, SeaTunnelDataType<?> valueType) {
if (!SqlType.STRING.equals(keyType.getSqlType())) {
throw new MongodbConnectorException(
CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION,
"JSON format doesn't support non-string as key type of map. The type is: "
+ typeSummary);
}
final SerializableFunction<Object, BsonValue> valueConverter =
createNullSafeInternalConverter(valueType);
return new SerializableFunction<Object, BsonValue>() {
private static final long serialVersionUID = 1L;
@Override
public BsonValue apply(Object value) {
Map<String, ?> mapData = (Map<String, ?>) value;
final BsonDocument document = new BsonDocument();
for (Map.Entry<String, ?> entry : mapData.entrySet()) {
String fieldName = entry.getKey();
document.append(fieldName, valueConverter.apply(entry.getValue()));View on GitHub (pinned to cf67b549a7)
Solutions
- Change the map key type to STRING in the SeaTunnel schema (e.g. MAP<STRING,STRING>) at the source or via a transform.
- Insert a transform that converts the offending map field to a JSON string or re-keys it as strings before the MongoDB sink.
- If integer keys are required, flatten the map into separate fields or store as an array of key/value documents instead.
Example fix
// before (schema)
fields { id = INT payload = MAP<INT, STRING> }
// after
fields { id = INT payload = MAP<STRING, STRING> } Defensive patterns
Strategy: validation
Validate before calling
if (mapType.getKeyType().getSqlType() != SqlType.STRING) {
throw new IllegalArgumentException(
"MongoDB sink requires MAP keys of type STRING, got: " + mapType.getKeyType());
} Type guard
static boolean hasStringMapKeys(SeaTunnelRowType rowType) {
return java.util.Arrays.stream(rowType.getFieldTypes())
.filter(t -> t instanceof SeaTunnelMapType)
.map(t -> (SeaTunnelMapType<?, ?>) t)
.allMatch(m -> m.getKeyType().getSqlType() == SqlType.STRING);
} Prevention
- Always declare MAP fields with STRING keys when targeting MongoDB.
- Review source schema inference output before wiring to the MongoDB sink.
- Add a transform stage to stringify maps with non-string keys.
When it happens
Trigger: Defining a SeaTunnel MAP field whose key SqlType is not STRING (e.g. MAP<Int, String>, MAP<Long, String>) and writing it to the MongoDB sink via createMapConverter.
Common situations: Users modeling keyed data with integer IDs (e.g. MAP<INT,STRING>) coming from relational sources or inline schemas; upstream schema inference produced integer map keys; hand-written schema in the config used a non-string key.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/da00992c6bb1a606.
Report an issue: GitHub.