How to store a UUID in MongoDB with Golang?

Due to the nature of github.com/google/uuid UUID type being an alias of [16]byte, Mongo will resort to storing it as a BSON Binary of subtype 0x00. It is impractical to attempt to convert the UUID to a base64 binary format for BSON. So you may choose to use this encoder & decoder feature I wrote that can be plugged directly into the mongo client struct here: https://gist.github.com/SupaHam/3afe982dc75039356723600ccc91ff77

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top