Your idea is probably difficult to implement in MongoDB. Your idea comes from the identity counter provided in many relational databases.
In MongoDB, if you need to sort blog posts, you can use time or other "fields" suitable for sorting.
For reference.
Love Mongo! Have Fun!
-->Poke me<--Please poke me on the left, it’s April! Sign up now!
Registration for the MongoDB Chinese Community Shenzhen User Conference has begun! The master of this forum will make a grand appearance at the conference and deliver a speech. There is applause here! ! !
If I understand correctly, no database can fulfill your request. Suppose I have 10,000 blogs now and I delete the first one. Do you want to regenerate IDs for the next 9,999 posts? What if there are 1 million blogs in total? So this idea itself is incorrect. If the purpose is only to record the order in which documents are published, the default _id usedObjectId完全可以满足你的需求。ObjectIditself is increasing and can be sorted. Regarding ObjectId, I wrote a blog to introduce related knowledge. If you are interested, please click here.
Your idea is probably difficult to implement in MongoDB. Your idea comes from the identity counter provided in many relational databases.
In MongoDB, if you need to sort blog posts, you can use time or other "fields" suitable for sorting.
For reference.
Love Mongo! Have Fun!
-->Poke me<--Please poke me on the left, it’s April! Sign up now!
Registration for the MongoDB Chinese Community Shenzhen User Conference has begun! The master of this forum will make a grand appearance at the conference and deliver a speech. There is applause here! ! !
If I understand correctly, no database can fulfill your request. Suppose I have 10,000 blogs now and I delete the first one. Do you want to regenerate IDs for the next 9,999 posts? What if there are 1 million blogs in total? So this idea itself is incorrect.
If the purpose is only to record the order in which documents are published, the default _id used
ObjectId
完全可以满足你的需求。ObjectId
itself is increasing and can be sorted.Regarding ObjectId, I wrote a blog to introduce related knowledge. If you are interested, please click here.