简体   繁体   English

mongoose findbyId() 显示“路径”参数必须是字符串类型。 收到模型的实例'

[英]mongoose findbyId() showing 'The "path" argument must be of type string. Received an instance of model'

so this is my code here (express)所以这是我的代码(快递)

    app.get('/:id', async (req,res) => {
        const id = req.params.id;
        console.log(id)
        const bids = await Bid.findById(id)
        res.render(bids)
    
    })

so this is what I got in the console所以这就是我在控制台中得到的

61671cef1c1db40b750502b0
(node:8068) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of model
    at validateString (internal/validators.js:124:11)
    at extname (path.js:828:5)
    at new View (D:\konectapp-1\node_modules\express\lib\view.js:56:14)
    at Function.render (D:\konectapp-1\node_modules\express\lib\application.js:570:12)
    at ServerResponse.render (D:\konectapp-1\node_modules\express\lib\response.js:1012:7)
    at D:\konectapp-1\app.js:62:9
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:8068) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:8068) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I can see it is providing the object id at the top of the console as I have logged, but when I passed it to the findbyid , it is giving me this error我可以看到它在我记录的控制台顶部提供了对象 id,但是当我将它传递给 findbyid 时,它给了我这个错误

...but when I passed it to the findbyid , it is giving me this error ...但是当我将它传递给 findbyid 时,它给了我这个错误

There seems to be nothing wrong with the mongoose findById() , although it's better to handle the errors properly when using async/await with a try/catch block.猫鼬findById()似乎没有任何问题,尽管在使用async/awaittry/catch块时正确处理错误会更好。

[ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string... [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型...

This throws from res.render(bids) .这是从res.render(bids)抛出的。

res.render() only accepts a string which is the file path of the view file to render. res.render()只接受一个字符串,它是要渲染的视图文件的文件路径。 But here you're passing an object as the parameter.但是在这里你传递一个对象作为参数。 See the documentation .请参阅文档

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 收到 Object 的实例 - TypeError [ERR_INVALID_ARG_TYPE]: The “path” argument must be of type string. Received an instance of Object ERR_INVALID_ARG_TYPE - “from” 参数必须是字符串类型。 接收到一个 Array 实例 - ERR_INVALID_ARG_TYPE - The “from” argument must be of type string. Received an instance of Array Nextjs -Express App.render“path”参数必须是string类型。 收到类型对象 - Nextjs -Express App.render The “path” argument must be of type string. Received type object 错误:“路径”参数必须是字符串类型。 收到未定义。 firebase deploy --only 功能 - Error: The “path” argument must be of type string. Received undefined. firebase deploy --only functions (hashlips_art_engine-1.1.2_patch_v5) “路径”参数必须是字符串类型。 收到未定义 - (hashlips_art_engine-1.1.2_patch_v5) The "path" argument must be of type string. Received undefined ytdl:“url”参数必须是字符串类型。 接收类型未定义 - ytdl: The "url" argument must be of type string. Received type undefined Webpack 类型错误'TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 接收类型布尔值(真)' - Webpack type error 'TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type boolean (true)' 图片上传错误:TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 接收类型未定义 - Image Upload Error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined TypeError [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 收到未定义和代码:'ERR_INVALID_ARG_TYPE' - TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined and code: 'ERR_INVALID_ARG_TYPE' Node.js 应用程序类型错误 [ERR_INVALID_ARG_TYPE]:“路径”参数必须是字符串类型。 接收类型对象 - Node.js app TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM