Uh, this is the old "surrogate key vs. non-surrogate (natural) key" discussion. This is a bit of a flame war...
I think surrogate keys (i.e. ObjectIds
) are the way to go. The key objections to the "natural" key (the official id card id) are these:
- You can't verify them. If the user entered a wrong number (but with a valid format), what do you do? Since primary keys can't be changed, you'll have to re-insert a new object and fix all links to the user. Ugly.
- You have no control of them. If the government decides to re-issue a number, you're out of luck
- Their format can change over time, which isn't a big problem for MongoDB but might be a problem in the code / in the API
- The natural key might expose information to the outside that shall remain secret for some/many users of the system. Suppose amazon would use your id card's number as a public identifier of your account.
...and a MongoDB-specific argument
- The
ObjectId
has a number of properties: it carries a timestamp and it's monotonic. Natural keys usually can't make such guarantees