我正在開發一個節點應用程序。所有路線似乎都有效,直到我添加app.get('/clients/:id',async (req, res) => { const client = await Client.findById(req.params.id); res.render('clients/show', {client});});當我注釋掉 id 路由時,新路由將按預期工作。但是當它在那里時,我嘗試點擊“新路線”:app.get('/clients/new', (req, res) => { res.render('clients/new')});我收到以下錯誤:(節點:17216)UnhandledPromiseRejectionWarning:CastError:對于模型“Client”的路徑“_id”處的值“new”,轉換為 ObjectId 失敗這是我的架構: const mongoose = require('mongoose'); const { Schema } = mongoose; const ClientSchema = new Schema({ company: String, contact: String, phone: Number, email: String, city: String, state: String, zip: Number, accounts: [ { type: Schema.Types.ObjectId, ref: 'Account', }, ] }); module.exports = mongoose.model('Client', ClientSchema);我似乎在這里找不到問題,任何幫助將不勝感激。
NodeJS:CastError:模型“Client”的路徑“_id”處的值“new”
RISEBY
2023-08-24 10:29:14