[英]Mongo db findOne query will not stop
我正在使用express js和angular js,但是我发现findOne方法不会结束。
对于每个请求,在执行CURD任务之前,后端函数将首先获取obj:
exports.article = function(req, res, next, id) {
Article.load(id, function(err, article) {
if (err) return next(err);
if (!article) return next(new Error('Failed to load article ' + id));
req.article = article;
next();
});
};
然后销毁它:
exports.destroy = function(req, res) {
var article = req.article;
article.remove(function(err) {
...
但是它永远不会进入销毁范围,因为它在出口中不断运转。
加载操作实际上是这样的:
ArticleSchema.statics.load = function(id, cb) {
this.findOne({
_id: id
}).populate('user', 'name username').exec(cb);
};
当我将其修改为:
exports.team = function(req, res, next, id) {
req.team = Team.findOne({_id: id});
};
它在无尽的运行中也一样...请帮助
我发现next(); 函数应该在执行的最后添加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.