【问题标题】:Route with populate() not working in production but works fine in local使用 populate() 的路由在生产中不起作用,但在本地运行良好
【发布时间】:2020-08-31 12:34:20
【问题描述】:

我正在根据 ID 填充用户的错误。 我已经按照所有步骤进行操作,并且能够在我的本地进行填充。但是当我将此代码部署到 heroku 时,它会抛出错误。 在下面发布必要的代码

路线:

let getAllBugs = async (req, res) => {
 
  let user = await userModel.findById(req.user._id)
  console.log("user->" + req.user);
  console.log(req.user)
 await user.populate("userBugs").execPopulate();

  res.send(user.userBugs);
};

型号:

userSchema.virtual('userBugs', {
  ref: 'Trackers',
  localField:'_id',
  foreignField:'owner'
})
  owner: {
    type: Mongoose.Schema.Types.ObjectId,
    required: true,
    ref: 'users',
  },

所有其他路线都在工作,所以当我到达上述路线时,我必须更新任何 w.r.t 生产环境。 它是否必须与异步做任何事情,因为我所有的其他路由都不是异步的?

请帮忙

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    我发现我的邮递员客户端中的 GET 请求存在问题。如果您遇到此问题,请从其他客户端尝试并验证您的路线。

    【讨论】:

      猜你喜欢
      • 2013-02-12
      • 2018-05-24
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 2021-06-14
      • 2016-02-26
      • 2019-06-13
      • 2019-12-14
      相关资源
      最近更新 更多