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).
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
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
The POST request after a while goes red
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. 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.
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 }
});
您没有在请求处理程序中发送任何响应。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.