Javascript 如何迭代对象数组,以便在Mongodb嵌套数组中推送数据

Javascript 如何迭代对象数组,以便在Mongodb嵌套数组中推送数据,javascript,arrays,mongodb,express,mongoose,Javascript,Arrays,Mongodb,Express,Mongoose,所以我正在开发一个博客应用程序,我现在正在编写一个在线编辑器,没什么特别的 在我开始解释我的问题之前,考虑一下我使用的这个模式: var blogSchema = restful.model('blog-schema', mongoose.Schema({ title: String, preview: String, content: [{tag: String, body: String}], comments: [{ body: String, date: Dat

所以我正在开发一个博客应用程序,我现在正在编写一个在线编辑器,没什么特别的

在我开始解释我的问题之前,考虑一下我使用的这个模式:

 var blogSchema = restful.model('blog-schema', mongoose.Schema({
   title: String,
   preview: String,
   content: [{tag: String, body: String}],
   comments: [{ body: String, date: Date}],
   createdAt: {type: Date, default: Date.now}
 }
在我的客户端,我使用
react
发布如下数据:

 [{"type":"h2","body":"azeaeazeae"},{"type":"p","body":"azeaeazeae"}]
然后在
express()中执行以下操作:

 blogSchema.update(
  {title: "please work AGAIN"},
  {
     $pushAll: {
      content: test
     }
 },
 function(err, stat, docs) {
  console.log(stat);
 }
)
然后,我与邮递员一起检查数据是否存储良好,并得出以下结论:

"content": [    
{
  "tag": "[object Object],[object Object]",
  "_id": "57b2eced869e03821d446c38"
}
我的问题是,如何在我的服务器中遍历这个对象数组,然后将每个项目推送到各自的位置:
标记和
正文

,我确实找到了它:

代码如下:

app.post('/admin', function(req, res) {
   var test = req.body;

   test.map(function(test, i) {
   blogSchema.update(
   {title: "please work AGAIN"},
    {
      $push: {
        content: {
          test: test.type,
          body: test.body
        }
      }
    },
    function(err,stat,dude){
      console.log(stat);
    })
})  

我简单地映射了req.body,然后在mongo中执行$push。。。我很抱歉发布了这个问题。尽管如此,我还是很高兴

还有一个问题,为什么mongodb为每个推送的元素创建一个_id?{“test”:“h2”,“body”:“Some body text”,“_id”:“57b2f1260397195a1f49ac64”}可能会给出评论中问题的答案。