使用mongodbembeddedJson数据

我正在用nodejs使用mongodb。 我刚开始使用mongodb。 我有一个查询。这里是我的mongdb文档:

{ "_id": ObjectId("564dacf84d52785c1d8b4567"), "content": "This blog created by karanSofat", "html": "<p>This blog created by karanSofat</p>\n", "saved_at": ISODate("2015-11-19T11:05:28.618Z"), "title": "my blog" } 

我想和这个数据联系起来。 我希望我的JSON应该在用户评论的时候。

 { "_id": ObjectId("564dacf84d52785c1d8b4567"), "comments": [ { "name": "arpit", "email": "arpit@gmail.com", "comment": "How can Make we this at good", "posted_at": ISODate("2015-11-19T11:06:03.628Z") }, { "name": "sumit", "email": "sumit@ggi.net", "comment": "this is also well for me", "posted_at": ISODate("2015-11-19T11:06:27.172Z") } ], "content"▼: "This blog created by karanSofat", "html": "<p>This blog created by karanSofat</p>\n", "saved_at": ISODate("2015-11-19T11:05:28.618Z"), "title": "my blog" } 

我正在使用angularjs和节点js.Here是我的代码:

 app.post('/comments/:id', function(req, res) { var id = req.params.id; var comments = JSON.parse(JSON.stringify(req.body)); res.json({data:id,data2:input}); }); 

做一个新的mongoose模型称为评论与结构:

 { name: { type: String }, email: { type: String }, comment: { type: String }, posted_at: { type: Date } } 

每个文档将被赋予它自己独特的_id。 保存每条评论时,请更新blog_post文档上的评论数组。 然后你可以利用Mongoose的内置“填充”function:

http://mongoosejs.com/docs/populate.html