简体   繁体   English

Mongo DB findOne查询不会停止

[英]Mongo db findOne query will not stop

I am using express js and angular js, but I found that the findOne method will not end. 我正在使用express js和angular js,但是我发现findOne方法不会结束。

For every request, the backend function will get the obj first before doing CURD stuff: 对于每个请求,在执行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();
    });
};

and then get to destroy it: 然后销毁它:

exports.destroy = function(req, res) {
    var article = req.article;

    article.remove(function(err) {
...

but it will never enter the destroy scope since it keeps endless running in exports.article. 但是它永远不会进入销毁范围,因为它在出口中不断运转。

the load operation is actually like this: 加载操作实际上是这样的:

ArticleSchema.statics.load = function(id, cb) {
    this.findOne({
        _id: id
    }).populate('user', 'name username').exec(cb);
};

when i modify it to: 当我将其修改为:

exports.team = function(req, res, next, id) {
    req.team = Team.findOne({_id: id});
};

it did the same with endless running...please help 它在无尽的运行中也一样...请帮助

I found that the next(); 我发现next(); function should be added in the last of execution. 函数应该在执行的最后添加。

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

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