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")
}
]
}
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.