Arrays 节点+;Mongo:将记录添加到集合内的数组
我正在写一个博客系统。现在我正在为帖子写评论。以下是每个帖子的模式:Arrays 节点+;Mongo:将记录添加到集合内的数组,arrays,node.js,mongodb,collections,Arrays,Node.js,Mongodb,Collections,我正在写一个博客系统。现在我正在为帖子写评论。以下是每个帖子的模式: { "topic": "Post Topic", "post": "<p>\r\n\tPost text</p>\r\n", "time_added": 1343167025, "author": "Ashley Brooks", "_id": { "$oid": "500f1a315759c73805000001" } }) 它返回给我这样的错误: exception: must speci
{
"topic": "Post Topic",
"post": "<p>\r\n\tPost text</p>\r\n",
"time_added": 1343167025,
"author": "Ashley Brooks",
"_id": {
"$oid": "500f1a315759c73805000001"
}
})
它返回给我这样的错误:
exception: must specify remove or update
我做错了什么
顺便说一句,我认为用任何唯一的id或类似的smth标记单独的评论是很好的。如何指定Mongo为每个添加注释添加obj_id参数?提前感谢。使用了“更新”功能,它起到了作用:
collection.update(
{_id: obj_id}, // query
{$push: {
comments: {comment: req.body.comment, name: "testname" }
}
},
使用“更新”后,效果良好:
collection.update(
{_id: obj_id}, // query
{$push: {
comments: {comment: req.body.comment, name: "testname" }
}
},
collection.update(
{_id: obj_id}, // query
{$push: {
comments: {comment: req.body.comment, name: "testname" }
}
},