ObjectId has 12 bytes and a total of 96 bits of information. If hexadecimal is used, each bit can provide 6 bits of information, so only 16 64-bits are needed. There are 62 letters + numbers in total, just find two punctuation marks :-)
The main principle is to create a new collection of counter counts in the database, record the maximum ID of each model, and then update the ID when saving. Use $inc in findAndModify to achieve increment. $inc is an atomic operation.
If it is an interface type, it will not be displayed directly in the browser address bar, so just use ObjectId.
If you are displaying an article, use: http://web/article/MongoDB存储的数据,标识怎样在URL显示的更简洁 is better and easier for people to understand.
Check this out: http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/
ObjectId has 12 bytes and a total of 96 bits of information. If hexadecimal is used, each bit can provide 6 bits of information, so only 16 64-bits are needed. There are 62 letters + numbers in total, just find two punctuation marks :-)
You can use numbers to increase your ID
Mongodb officially provides a solution for self-increasing ID, please refer to
http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/
The main principle is to create a new collection of counter counts in the database, record the maximum ID of each model, and then update the ID when saving. Use $inc in findAndModify to achieve increment. $inc is an atomic operation.
Create a new field to store the ID. When storing, take a screenshot.
Or use a customized Slug.
If it is an interface type, it will not be displayed directly in the browser address bar, so just use ObjectId.
If you are displaying an article, use:
http://web/article/MongoDB存储的数据,标识怎样在URL显示的更简洁
is better and easier for people to understand.