2014-05-06 41 views
0

我的req.body已成功到达mongodb数据库中的嵌套模型,但控制台显示挂起的POST请求(下面的img,请求会永久显示加载图标)。POST请求悬挂,mongodb和快速?

enter image description here

这里是如何更新数据的路由设置

router.post('/api/teams/:tid/players', player.add);

然后MongoDB的添加查询这在技术上更新现有的团队,但增加了内部的新对象给玩家阵列该模型

add: function(req, res) { 
    models.Team.findOneAndUpdate({ _id: req.params.tid }, { $addToSet: { players: req.body} }, function(err, doc){ 
       console.log(doc); 
    }); 
} 

我的命令行显示POST是成功的200 enter image description here

一段时间后,POST请求云红

enter image description here

所以我希望这是没有道理的错误,我做的,但我的问题是什么原因造成的岩石POST请求,它的工作原理,但它不是很流畅,需要修复。这也没有多大意义,所以我希望有人能指出。这可能与我的mongodb查询有关,因此让我向您展示我的Team SCHEMA,只是为了向您展示如何添加到它中。

var Team = new Schema({ 
    team_name: { type: String }, 
    players: [ 
     { 
      player_name: { type: String }, 
      points:  { type: Number }, 
      made_one:  { type: Number }, 
      made_two:  { type: Number }, 
      made_three: { type: Number }, 
      missed_one: { type: Number }, 
      missed_two: { type: Number }, 
      missed_three: { type: Number }, 
      percentage: { type: Number }, 
      assists:  { type: Number }, 
      rebounds:  { type: Number }, 
      steals:  { type: Number }, 
      blocks:  { type: Number }, 
      fouls:  { type: Number }, 
      feed:   { type: String }, 
      facebook_id: { type: Number } 
     } 
    ], 
    points:  { type: Number }, 
    made_one:  { type: Number }, 
    made_two:  { type: Number }, 
    made_three: { type: Number }, 
    missed_one: { type: Number }, 
    missed_two: { type: Number }, 
    missed_three: { type: Number }, 
    percentage: { type: Number }, 
    assists:  { type: Number }, 
    rebounds:  { type: Number }, 
    steals:  { type: Number }, 
    blocks:  { type: Number }, 
    fouls:  { type: Number }, 
    feed: { type: String } 
}); 

回答

5

您没有在您的请求处理程序中发送任何响应。

+0

哦,所以我需要'res.json(doc)' – Mike

+0

我只是按照我所看到的,我对这个查询有一些帮助,我不知道我需要发送一个资源,我一直这样做,但我没有知道这是特别需要POST请求,现在尝试:) – Mike

+0

感谢它的工作! :)将接受这一点,当我可以约5分钟 – Mike