CastError:对于值“ {userId:'5c48a95df9bd9a33c0ff9405”的转换为ObjectId失败

时间:2019-02-01 13:05:57

标签: typescript

对于模型“路径”的“用户”,在值“ {userId:\'5c48a95df9bd9a33c0ff9405 \',\ n用户名:\'ahsan \',\ n iat:1549024353,\ n exp:1549110753}”中,对对象ID的投射失败“出租””

router.get("/manage", UserControl.loginMiddleware, (req, res) => {
const user = res.locals.user;
Rental.where({ user })
.populate("bookings")
.exec((err, foundRentals) => {
  if (err) {
    return res.status(422).send({ errors: mongoErrors(err.errors) });
  }
  return res.json(foundRentals);
  });
});

1 个答案:

答案 0 :(得分:0)

router.get("/manage", UserControl.loginMiddleware, (req, res) => {
const user = res.locals.user;
Rental.where("user",user.userId)
.populate("bookings")
.exec((err, foundRentals) => {
  if (err) {
  return res.status(422).send({ errors: mongoErrors(err.errors) });
     }
 return res.json(foundRentals);
   });
});