亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

mongodb - 評(píng)論放在list里,怎么為每條評(píng)論創(chuàng)建唯一標(biāo)識(shí)符id?
天蓬老師
天蓬老師 2017-04-21 11:17:54
0
3
880

MongoDB里,我將評(píng)論以dict形式存放在list里,由于要考慮到評(píng)論的修改和刪除,所以不知道怎樣給這些評(píng)論創(chuàng)建id,各位有沒(méi)有好辦法?

{
        "_id" : ObjectId(),
        "comments" : [
                {
                        "id" : '#就是這里的id#',
                        "text" : "",
                },
        ]
}
天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見(jiàn)證您的進(jìn)步~~

reply all(3)
伊謝爾倫

Can you use MongoDB’s ObjectId

UPDATE:

Comments should be attached to the article, not subordinate to the article

So, create another collection, put comments, and then it contains an indexed field pointing to the 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 are no comments
When adding a new one, assign the new id and comments_max_id to comments_max_id+1 at the same time
Deleting will not affect other replies

阿神

ObjectId() and the index of comments can determine a comment

ObjectId() and 0 can be known to be the first reply to the article with id = ObjectId()

If you need to manage all replies, use the method above

左手右手慢動(dòng)作

You can create an auto-increment ID for a subdocument

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template