How to realize self-increasing id in mongo? after deleting one id, all ids will be reordered?

  mongodb, question

I want to use id(1-n) to record the order of blog posts, and find one on the Internet.Method, by adding a sequence table, but this method has a disadvantage, that is, once one of the articles is deleted, the other id will not change, so we can find a better method.

It is difficult to realize your idea in MongoDB. Your idea stems from the counter that provides identity in many relational databases.

In MongoDB, if you need to sort blog posts, you can use time or other “field” suitable for sorting.

For reference.

Love Mongo! Have Fun!


–>Poke me<-please poke the left, it’s in April! Sign up quickly!

MongoDB Chinese Community Shenzhen User Conference Begins Registration! The great spirit of this forum will be ceremoniously introduced and delivered a speech at the conference. Applause here! ! !