首页 > 解决方案 > CastError:模型“User”的路径“_id”处的值“app.css”转换为 ObjectId 失败

问题描述

app.get("/my/:id",isLoggedIn,function(req,res){
User.findById(req.params.id,function(err,user){
    if(err){
        console.log(err);
        res.redirect("/");
    }else{
        console.log(user);
        res.render("profile",{user:user});
    }   
});

});

这是我的代码,我的 css 文件在此页面上没有加载,而在其他页面上加载

标签: cssnode.jsexpressmongoose

解决方案


正如错误所说:值被传输到只接受可以转换为 ObjectId 的值app.css的 db 查询 ( )。User.findById(...)


推荐阅读