简体   繁体   English

我正在尝试使用以下代码通过 postman 将一些数据发布到 mongo compass atlas 但收到此错误

[英]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.

相关问题 POST 请求正在使用 POSTMAN,但是当我尝试使用 Axios 从浏览器(UI)调用相同的链接时,它显示 404 错误 | node.js - POST request is working using POSTMAN, but when I'm trying to call the same link using Axios from browser(UI) it's showing 404 error | node.js 我想获取我的 Graph API 令牌,但出现错误,我正在使用 HttpServices 发出 POST 请求。 我收到 400 状态码。 我正在使用 NestJS - I want to get my Graph API token but I got an error, I'm making a POST request with HttpServices. I'm getting a 400 status code. I'm using NestJS 尝试使用 postman API 发布数据时出现错误“非法 arguments:字符串,未定义” - Having an error " Illegal arguments: string, undefined " while trying to post data using postman API 我正在尝试找出以下json数据出了什么问题 - I'm trying to figure out whats wrong with the following json data 我正在尝试按照老师的指示使用 img.src 在 JS 上获取一些照片,但代码不起作用。 我的代码看起来完全一样 - I'm trying to get some photos on JS using img.src as my teatcher instructed but the code won't work. My code looks exactly the same tho 我是使用 Knockout js 的新手,我尝试显示一个列表,但出现以下错误 - I'm new using Knockout js, I try to show a list and I get the following error 尝试打印一些JSON数据时出现错误“ null or not object” - I'm getting an error “null or not an object” when trying to print some JSON data 请参考我的以下代码。我想使用ajax在视图中显示数据,但出现错误[对象] - please refer my following code.i want to display data in view by using ajax but i get error[obect object]] 我正在尝试获取 localStorage 但遇到错误 - I'm trying to get the localStorage but encountering an error 我正在从邮递员和JS代码向Web服务发送POST-响应不同,为什么? - I'm sending POST to my webservice from postman and from my JS code - the response differ, why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM