当转到用户路线时,首先它返回文档 . 再次(我不重启),它返回null . 这是代码:

app.get("/author/:name", function(req,res,next) {
         Article.find({ author : req.params.name},function(err,allArticle) {  // find all documents associated with the name
            if(err) {
              console.log(err);
              next();  
            } else {
              res.locals.article = allArticle;
              next();              
            }
        })
     }, function(req,res) {
         User.findOne({username : req.params.name}, function(err,user) {
           if(err) {       // find user with the name in the route
              console.log(err);
            } else {
            console.log(user);
            res.locals.user = user;
            res.locals.user.bio = marked( user.bio );
            res.render("showAuthor", res.locals);
     }
    })
  })

Output

这意味着“user”为空,当它刚刚将它返回给我们时 . 另外,我用“文章”和相同的输出尝试了它 .

不知道为什么这种奇怪的行为正在发生,只有这条路线!

如果有人能帮助我,那就太好了 .

谢谢!