Comments are placed in the list. how do you create a unique identifier id for each comment?

  mongodb, question

In MongoDB, I put the comments in the list in the form of dict. I don’t know how to create id for these comments due to the modification and deletion of comments. Do you have any good methods?

{
        "_id" : ObjectId(),
        "comments" : [
                {
                        "id" : '#就是这里的id#',
                        "text" : "",
                },
        ]
}

Can you use MongoDB’s ObjectId

UPDATE:

Comments should be attached to articles, not articles.

So, set up another collection, put comments, and then it contains an indexed field that points to objid of the article.

@felix021: Well, add a field for the current maximum floor, and the deleted floor will not affect other floors.

{
        "_id" : ObjectId(),
        "comments_max_id" : int,
        "comments" : [
                {
                        "id" : int,
                        "text" : "",
                },
        ]
}

Comments_max_id starts from 1 and is 0 when there is no comment.
When adding, the new id and comments_max_id are both assigned comments_max_id+1
The deletion will not affect other replies.