[英]I'm trying to post some data through postman into mongo compass atlas using the following code but get this error
TypeError: Cannot read property 'id' of undefined TypeError:无法读取未定义的属性“id”
exports.createPost = asyncHandler(async (req,res,next)=>{
//Add user to reqbody
req.body.user = req.user.id
const post = await Post.create(req.body)
res.status(201).json({
success:true,
data:post
})
})
I'm not sure but looks like the object req.user
on what you are trying to access the id prop is undefined
我不确定,但看起来 object
req.user
关于您尝试访问的 id 道具undefined
Check req.user.id
, req.user - undefined.检查
req.user.id
, req.user - 未定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.