ejs中未定义的猫鼬诺言

问题描述 投票:0回答:1
```statsRoute.route("/getPlayerInfos").get(function (req, res) {

让统计信息= User.findOne({名称:req.body.myquery,角色:0,})。populate({路径:“商店”,型号:“商店”,填充:{路径:“ WorldDetails”,模型:“ WorldDetails”},填充:{路径:“游戏”,型号:“游戏”,填充:{路径:“详细信息”,模型:“详细信息”},},})。exec();让myres = statistics.toObject({getters:true});res.render(“ stats”,{myres});});```

node.js mongoose promise ejs
1个回答
0
投票

您的代码缺少承诺解析。试试这个,

statsRoute.route("/getPlayerInfos").get(async function (req, res) {
  let statistics = await User.findOne({
    name: req.body.myquery,
    role: 0,
  }).populate({
      path: "Stores",
      model: "Store",
      populate: { path: "WorldDetails", model: "WorldDetails" },
      populate: {
        path: "Games",
        model: "Game",
        populate: { path: "Details", model: "Detail" },
      },
    }).exec();
  // Object
  let myres = statistics.toObject({ getters: true });
  res.render("stats", { myres });
});
© www.soinside.com 2019 - 2024. All rights reserved.