gpt4 book ai didi

node.js - Mongoose Actor 错误

转载 作者:太空宇宙 更新时间:2023-11-04 00:05:41 24 4
gpt4 key购买 nike

我有以下代码,它绝对不执行任何操作,并且由于某些原因,我的 mongoose 出现错误,甚至没有被调用,这是代码:

.post('/testRequest', express.json(), upload.none(), async (req, res) => {
try {
res.status(200);
res.send('test');
} catch (err) {
console.error(err.stack);
res.status(err.code || 400);
res.send(err.message || err);
}
})

这是错误:

message: 'Cast to ObjectId failed for value "test" at path "_id" for model "Requests"',
name: 'CastError',
stringValue: '"test"',
kind: 'ObjectId',
value: 'test',
path: '_id',
reason: undefined,

我尝试了很多方法,但似乎没有解决

最佳答案

您的代码顶部可能有一个 .post(':id', ...) 。因此,对 /testRequest 的 post 请求与 '/:id''/testRequest' 路由匹配,但只有最上面的一个执行。':id' 路由读取 testRequest 作为 ID 并抛出 CastError。

您可以交换方法的顺序,这已经讨论过 here .

关于node.js - Mongoose Actor 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52397778/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com