{"record":{"id":"b6f619b704bc8221","repo":"apache/seatunnel","slug":"value-is-not-a-bson-date-or-timestamp","errorCode":null,"errorMessage":"Value is not a BSON date or timestamp","messagePattern":"Value is not a BSON date or timestamp","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/serialize/DocumentDBItemDeserializer.java","lineNumber":197,"sourceCode":"            return value.asString().getValue();\n        }\n        if (value.isObjectId()) {\n            return value.asObjectId().getValue().toHexString();\n        }\n        if (value.isDocument()) {\n            return value.asDocument().toJson(RELAXED_JSON_SETTINGS);\n        }\n        return value.toString();\n    }\n\n    private static LocalDateTime convertDateTime(BsonValue value) {\n        Instant instant;\n        if (value.isDateTime()) {\n            instant = Instant.ofEpochMilli(value.asDateTime().getValue());\n        } else if (value.isTimestamp()) {\n            instant = Instant.ofEpochSecond(value.asTimestamp().getTime());\n        } else {\n            throw new IllegalArgumentException(\"Value is not a BSON date or timestamp\");\n        }\n        return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());\n    }\n\n    /** Converts array elements recursively so nested rows, maps, and arrays use the same rules. */\n    private Object convertArray(String field, ArrayType<?, ?> type, BsonValue value) {\n        List<BsonValue> source = value.asArray();\n        Object target = Array.newInstance(type.getElementType().getTypeClass(), source.size());\n        for (int i = 0; i < source.size(); i++) {\n            Array.set(target, i, convert(field, type.getElementType(), source.get(i)));\n        }\n        return target;\n    }\n\n    /** Converts BSON documents to maps; BSON field names require a string map key type. */\n    private Map<String, Object> convertMap(String field, MapType<?, ?> type, BsonValue value) {\n        if (type.getKeyType().getSqlType() != SqlType.STRING) {\n            throw conversionError(field, type);","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-amazondocumentdb/src/main/java/org/apache/seatunnel/connectors/seatunnel/amazondocumentdb/serialize/DocumentDBItemDeserializer.java#L179-L215","documentation":"DocumentDBItemDeserializer.convertDateTime expects a BSON value of type DateTime or Timestamp to produce a LocalDateTime. If the BSON value is any other type (string, int32, null, etc.) it throws this IllegalArgumentException, because SeaTunnel's timestamp column requires an actual BSON date/timestamp value.","triggerScenarios":"A document field declared as TIMESTAMP in the SeaTunnel schema contains a BSON string (e.g. \"2024-01-01T00:00:00Z\") or numeric value instead of a BSON Date (ISODate) or BSON Timestamp.","commonSituations":"Documents written by different applications with inconsistent typing; data migrated from another store as plain strings; schema mapping declared the field as TIMESTAMP while the collection stores ISO-8601 strings.","solutions":["Fix the data in DocumentDB to store the value as a BSON Date ($toDate in an update pipeline).","Change the SeaTunnel schema column to STRING if the source stores date strings, then transform/parse downstream.","Add a transform (e.g. with a custom deserializer or Transform) that parses string dates into timestamps before this converter runs."],"exampleFix":"// before: document stores {\"ts\": \"2024-01-01T00:00:00Z\"} mapped to TIMESTAMP\n// after: convert in MongoDB/DocumentDB\n db.coll.updateMany({}, [{ $set: { ts: { $toDate: \"$ts\" } } }])","handlingStrategy":"type-guard","validationCode":"if (!(bsonValue.isDateTime() || bsonValue.isTimestamp())) {\n    throw new IllegalArgumentException(\"Field must be BSON Date or Timestamp, got: \" + bsonValue.getBsonType());\n}","typeGuard":"boolean isBsonDateLike(BsonValue v) { return v != null && (v.isDateTime() || v.isTimestamp()); }","tryCatchPattern":"try { value = convertDateTime(field, type, bsonValue); } catch (IllegalArgumentException e) { log.warn(\"Non-date value for {}: {}\", field, bsonValue); handleNull(); }","preventionTips":["Ensure all writers store BSON Dates (ISODate), not ISO strings or epoch ints.","Run $type checks: db.coll.find({ ts: { $type: { $nin: ['date','timestamp'] } } }).","Map string date columns to STRING in the schema and parse in a transform."],"tags":["java","documentdb","datetime","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}