猫鼬模型查询未按顺序进行

时间:2020-10-20 11:20:09

标签: node.js express mongoose

我正在构建一个非常简单的应用程序,可以查看约会。我需要搜索特定用户的约会并显示当天的信息。我有两个集合,用户和约会。我的问题是代码似乎没有按顺序运行。这是我的get语句的摘录。我什至还用控制台记录了事件的顺序。

    app.get("/mycalendar", function (req, res){
    console.log("Before authentication");
    if (req.isAuthenticated()){
        console.log("Before find by ID");
        User.findById(req.user.id, function(err, foundUser){
            console.log("when user found");
        });
        console.log("before render")
        res.render("mycalendar", {
            dateSelected: dateSelect
        });
        console.log("After Authenticated");
    } else {
        res.redirect("/login");
    }
    console.log("end of get");
});

我从控制台获得的结果是: nodemon]开始node app.js 服务器在端口3000上启动 认证前 通过ID查找之前 渲染之前 认证后 获得结束 用户找到时

我已登录并通过用户身份验证。

0 个答案:

没有答案