Reputation: 1143
I am designing the schema for a simple MongoDB database where there will be a collection for customers.
Natural way of identifying customer will be use their official identification card id (6 numbers and a letter, unique for each person in the country). Another way of doing will be letting MongoDB to choose the _id field value and using the card id as another field.
Any suggestion of advantages / disadvantages of choosing one string with 6 numbers and a letter as _id, or choosing and ObjectId created by Mongo?
Upvotes: 5
Views: 270
Reputation: 46341
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:
...and a MongoDB-specific argument
ObjectId
has a number of properties: it carries a timestamp and it's monotonic. Natural keys usually can't make such guaranteesUpvotes: 4