简体   繁体   English

POST请求挂起,mongodb和Express吗?

[英]POST request hanging, mongodb and express?

My req.body is successfully reaching the nested model in the mongodb database, but the console shows a hanging POST request (img below, the request shows the loading icon forever). 我的req.body已成功到达mongodb数据库中的嵌套模型,但是控制台显示了一个挂起的POST请求(下面的img,该请求永远显示加载图标)。

在此处输入图片说明

Here is how the route to update that data is set 这是设置数据更新路线的方式

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

Then the mongodb add query which technically updates an existing Team but adds a new object to the players array within that model 然后mongodb添加查询,该查询从技术上更新了现有团队,但向该模型内的玩家数组添加了新对象

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

My command line shows that the POST was a success 200 我的命令行显示POST成功200 在此处输入图片说明

The POST request after a while goes red 一段时间后的POST请求变成红色

在此处输入图片说明

So I hope this is a no brainer mistake I made, but my question is what is causing a rocky POST request, it works but it is not very smooth and needs to be fixed. 因此,我希望这是一个我不会犯的错误,但是我的问题是什么导致了棘手的POST请求,它可以工作,但不是很顺利,需要修复。 It also doesn't make much sense, so I am hoping someone can point it out. 这也没有多大意义,所以我希望有人可以指出这一点。 It might have to do with my mongodb query, so let me show you my Team SCHEMA just to show you how I am adding into it. 它可能与我的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 }
});

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM