javascript - Mongodb data update questions?
黄舟
黄舟 2017-07-04 13:44:17
0
1
1206

mongodb How to update the replies array (add and delete) of the specified _id in comments?

{
    "_id" : ObjectId("595111698cce5d034f60ae79"),
    "title" : "Flower ribbon H skirt",
    "desc" : "간딘스키 작품같은 느낌의 플라워 프린팅\n\n앞면은 랩 스커트 느낌이 연출되고\n뒷면은 밴딩으로 되어 있어\n66사이즈이신 분까지 착용가능한데요\n",
    "createTime" : "Mon Jun 26 2017 21:51:37 GMT+0800 (CST)",
    "comments" : [
        {
            "_id" : ObjectId("5959f338c465d90f75d8544d"),
            "comment" : "qeqweqwe",
            "replys" : [ ],
            "createTime" : ISODate("2017-07-03T07:33:12.072Z")
        },
        {
            "_id" : ObjectId("5959f756034ffb103ea3bf41"),
            "comment" : "qweqweq",
            "replys" : [ ],
            "createTime" : ISODate("2017-07-03T07:50:46.642Z")
        }
    ]
}
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(1)
学霸

I can’t think of a way to directly manipulate the document because I don’t know the position of the comment to be manipulated in the array.

You can first find the doc, get the object, then operate the comments (pure JavaScript), and then update the document.

You can also consider storing comments in separate tables to make it easier to operate.

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