There are no specific rules, regulations, nor protocols that apply to define a unique custom key, however, there are two criteria that stand out. The key you choose should be the following:
- Unique
- Meaningful
Usually, in order to achieve uniqueness, some sort of random strategy needs to be employed. Using a value derived from the year, month, day, hours, minutes, and seconds might be of use. You can also use bits from other fields within the document to build a unique key that is meaningful.
As an example, in the BigLittle Micro Finance Ltd. scenario, each borrower or lender has information stored in the users collection. Each document, in addition to the automatically generated ObjectId, has a unique userKey field. As you can see from the following screenshot, the key consists of the first 4 letters of first and last names with a random 4-digit number: