database schema - Use official identification card id or generated id's from MongoDB for identifying users? -
i designing schema simple mongodb database there collection customers.
natural way of identifying customer use official identification card id (6 numbers , letter, unique each person in country). way of doing letting mongodb choose _id field value , using card id field.
any suggestion of advantages / disadvantages of choosing 1 string 6 numbers , letter _id, or choosing , objectid created mongo?
uh, old "surrogate key vs. non-surrogate (natural) key" discussion. bit of flame war...
i think surrogate keys (i.e. objectids
) way go. key objections "natural" key (the official id card id) these:
- you can't verify them. if user entered wrong number (but valid format), do? since primary keys can't changed, you'll have re-insert new object , fix links user. ugly.
- you have no control of them. if government decides re-issue number, you're out of luck
- their format can change on time, isn't big problem mongodb might problem in code / in api
- the natural key might expose information outside shall remain secret some/many users of system. suppose amazon use id card's number public identifier of account.
...and mongodb-specific argument
- the
objectid
has number of properties: carries timestamp , it's monotonic. natural keys can't make such guarantees
Comments
Post a Comment