我在亚马逊 ec2 实例上有一个带有 mongo 服务器的节点应用程序。它工作得很好,但我只是添加了一个新的 API 调用,每次调用它时,服务器都会冻结,我无法访问/ssh 几个小时。发生这种情况时,我的服务器出现故障,这使得依赖它的应用程序无法使用,我的用户很生气......
这段代码在我的 localhost 上运行良好,但是一旦我在我的服务器上运行它,它就会冻结。我的想法是它可能会崩溃 mongo?我不知道为什么会发生这种情况......
如果有人有任何想法可能会出错,请告诉我。
节点正在使用快递。send_error 函数将执行 res.send({some error})。db.CommentModel 返回 mongoose.model('comment', Comment);
在 app.js 中
app.get('/puzzle/comment/:id', auth.restrict, puzzle.getComments);
在定义 getComments 的文件中
exports.getComments = function(req, res)
{
var userID = _u.stripNonAlphaNum(req.params.id);
var CommentModel = db.CommentModel;
CommentModel.find({user: userID}, function(e, comments) {
if(e)
{
err.send_error(err.DB_ERROR, res);
}
else if (!comments)
{
err.send_error(err.DB_ERROR, res);
}
else if (comments.length == 0)
{
res.send([]);
}
else
{
var commentIDs = [];
for (var i = 0; i<comments.length; i++)
{
commentIDs.push({_id: comments[i].puzzle});
}
var TargetModel = pApp.findPuzzleModel(_u.stripNonAlphaNum(req.apiKey));
TargetModel.find({removed: false, $or: commentIDs}, function(e, puzzles) {
if(e)
{
err.send_error(err.DB_ERROR, res);
}
else if (!puzzles)
{
err.send_error(err.DB_ERROR, res);
}
else
{
res.send(puzzles);
}
});
}
});
}