I am looking at this article as I want to create a Comments System with Nodejs and MongoDB:
https://docs.mongodb.org/ecosystem/use-cases/storing-comments/
There are 3 methods to implement a comments system as it mentioned in this article, and the 1st method is to save a comment as a single document.
In the 1st method, the article uses a "slug" (for example, '34db') for each comment that is going to be saved in MongoDB. This "slug" is used to sort the comments, so it must be unique.
My question is, given the situation that when the comment is being created, the _id of the comment (MongoDB assigns an Object.id automatically to a saved object ) is unknown, how can we create such an unique "slug" for the comment that we are going to save?
In the article mentioned above, it uses a pseudo-method called "generate_pseudorandom_slug()". And I wonder how we can implement such an method in the real situation, to get something unique like "34db" for a comment?
Thank you!