apache/seatunnel · error · MongodbConnectorException
UNSUPPORTED_OPERATION
UNSUPPORTED_OPERATION
Error message
Bson format doesn't support non-string as key type of map. The type is: ${typeSummary} What it means
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).
Source
Thrown at seatunnel-connectors-v2/connector-mongodb/src/main/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/BsonToRowDataConverters.java:311
+ bsonValue
+ "' of type "
+ bsonValue.getBsonType());
}
List<BsonValue> in = bsonValue.asArray();
Object arr = Array.newInstance(type.getElementType().getTypeClass(), in.size());
for (int i = 0; i < in.size(); i++) {
Array.set(arr, i, elementConverter.apply(in.get(i)));
}
return arr;
}
};
}
private static SerializableFunction<BsonValue, Object> createMapConverter(
String typeSummary, SeaTunnelDataType<?> keyType, SeaTunnelDataType<?> valueType) {
if (!keyType.getSqlType().equals(SqlType.STRING)) {
throw new MongodbConnectorException(
UNSUPPORTED_OPERATION,
"Bson format doesn't support non-string as key type of map. The type is: "
+ typeSummary);
}
SerializableFunction<BsonValue, Object> valueConverter =
createNullSafeInternalConverter(valueType);
return new SerializableFunction<BsonValue, Object>() {
private static final long serialVersionUID = 1L;
@Override
public Object apply(BsonValue bsonValue) {
if (!bsonValue.isDocument()) {
throw new MongodbConnectorException(
ILLEGAL_ARGUMENT,
"Unable to convert to rowType from unexpected value '"
+ bsonValue
+ "' of type "View on GitHub (pinned to cf67b549a7)
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.
Example fix
// before scores = MAP<INT, DOUBLE> // after scores = MAP<STRING, DOUBLE>
Defensive patterns
Strategy: validation
Validate before calling
// Validate map key type before building the schema
if (mapType.getKeyType().getSqlType() != SqlType.STRING) {
throw new IllegalArgumentException(
"MongoDB connector requires MAP keys to be STRING, got: " + mapType.getKeyType());
} Try / catch
try {
buildSchema(options);
} catch (MongodbConnectorException e) {
if (e.getMessage().contains("non-string as key type of map")) {
// switch the map key type to STRING or restructure as ARRAY<ROW<k,v>>
} else { throw e; }
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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/d07f149b3fb35fd9.
Report an issue: GitHub.