【发布时间】:2018-11-23 02:06:07
【问题描述】:
我收到了一个猫鼬查询,我想在其中更改评论。我从一个反应应用程序收到评论 ID。但它不起作用,可能是什么问题?
下面是一个示例注释数组
"comments": [
{
"createdAt": "2018-11-22T08:28:36.881Z",
"_id": "5bf668b4001de72dc089c849", // commentid
"comment": "111111111111",
"username": "kohahn21"
},
....
]
我尝试过的:
edit = await Post.update(
{ 'comments._id' : commentid },
{ '$set' : { 'comments.$.comment' : comment } },
{ new: true }
);
ctx.body = edit;
ctx.body
{
"n": 1,
"nModified": 1,
"ok": 1
}
发布架构
const Comment = new Schema({
createdAt: { type: Date, default: Date.now },
username: String,
comment: String
});
const Post = new Schema({
username: String,
comments: {
type: [Comment],
default: []
},
});
module.exports = mongoose.model('Post',Post);
我想收到 cmets,这是一个修改后的评论布局。我该怎么办?
【问题讨论】:
标签: node.js mongodb mongoose mongodb-query