UUIDs not being inferred by Mongo Spark Connector when writing

I’m trying to write UUIDs from a dataframe into MongoDB via mongo-spark-connector. Since Spark does not have a UUID datatype, they are StringType in the dataframe. They also remain strings when written to MongoDB, instead of ‘UUID()’. Is there a way to write UUIDs to MongoDB via Spark such that they are loaded as ‘UUID()’?

Ex. in mongo:
id: “825687f0-16f8-4912-b911-c46a072c499a”
id: UUID(“825687f0-16f8-4912-b911-c46a072c499a”)

1 Like