DEV Community

Discussion on: From monolith to cloud: Auto Increment to UUID

Collapse
 
biros profile image
Boris Jamot ✊ /

I just switched from a PHP/MySQL app with auto-incremented ID to a Go/Mongodb app with UUID.
The main drawback I noticed is that you can't use internal mongodb document's ObjectId for your queries. It makes your code a bit more complex:

With auto-increment:

query := collection.FindId(1)

With UUID:

query := collection.Find(bson.M{"id": "123e4567-e89b-12d3-a456-426655440000"})

And it's the same for update, remove & upsert.

Collapse
 
bgadrian profile image
Adrian B.G. • Edited

Yes because ObjectID is a BSON object, and adds more text along the way.

You can use other types, like a string with a UUID, but you have to provide the _id at insert and you have to be sure they are unique. MongoDB will add an _id only if is missing and it will be an ObjectId.