meetM
Convex Community5mo ago
2 replies
meet

_id or separate "pkey" ID

tl;dr: Is it best practice to use a custom field (generated with UUID) as primary key, or use the built in _id that is generated.

Context:
Right now, I have a collection of tables:
users
, documents, documentFragments etc. Each have their own unique "primary key", so for example, in the users table, I have a field userID, in the documents table, I have documentID, etc.

In schema.ts, I'm linking together using the v.id, so for example, each document fragment has a field sourceDocument: v.id('documents').

At this point, is it even worth it to have the primary key UUID field (outside of the userID, since that is matching up with Clerk). That is, should I just remove the documentID and fragmentID field, and just use the _id that is generated? I originally had the custom field so I could "tag" them with a prefix that denoted what type, so for example: "doc_<UUID>".
Was this page helpful?