MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

Import UUID from CSV using "mongoimport"

We would like to import UUIDs from CSV using “mongoimport”. According to the documentation it is possible to “type” the columns to import. Unfortunately there is no “type” available for UUIDs. Luckily there is a “binary” type present which enables us to encode the UUID as “base64”.

We were able to encode UUIDs as “base64” based on the following code.

So far so good…

We are able to use “mongoimport” the “–columnsHaveTypes” flag and the fields defined as " uuid.binary(base64)". The problem/challenge is to change the “binary subtype”. Right now the default subtype “0” is being used which results in something like this: “BinData(0,“7tW06cUkR2+lOWIRssit5A==”)”. Is there a way to change the “binary subtype” to “4”?

Thank you.