What data type is commonly used to store foreign key id in mongodb

  mongodb, question

What is the best practice for storing foreign key id in mongodb? For example, if a user id is to be stored in an article, should the foreign key id of this user be of String type or ObjectId type?

clipboard.png

There are many advantages to using ObjectId as much as possible.
For example, it contains time information, which can be sorted by time directly with ObjectId.
For example, its rules support that id generated in the same mongo cluster are not repeated, which is an efficient hashing algorithm.
These things may seem simple, but in fact they are all big problems, especially the distributed hash algorithm, which is not so easy to handle. Try not to ask for trouble.