我的應用程序本地工作,但在生產中我似乎無法使用貓鼬蒙戈獲取一個具體的事情。我已經試過:演員到的ObjectId失敗的價值「」在路徑「_id」爲模型「教練」
var Coach = mongoose.model('Coach', CoachSchema);
Coach.findOne({ _id: req.session.userId}, function (err, coach) {})
Coach.find({ _id:req.session.userId}, function (err, coach) {})
Coach.findById(req.session.userId).exec(function(err, coach)){})
我已經收到了同樣的錯誤: Cast to ObjectId failed for value "586bc06bd09d870012baa5b8" at path "_id" for model "Coach"
就像我說的,這既nodemon
和heroku local
本地的作品,但我的Heroku生產服務器上它不工作。
我讀過一些關於這種類型拈錯誤:
- What's Mongoose error Cast to ObjectId failed for value XXX at path "_id"?
- Mongoose refuses to cast valid string to ObjectId
- Cast to ObjectId failed for value "586cc8b3ea780c071bbe2469" at path "_id" for model "User"
,但沒有運氣呢。任何幫助都會很棒。先謝謝你。
的可能的複製[投射到的ObjectId失敗值「586cc8b3ea780c071bbe2469」的路徑「\ _id」爲模式的「用戶」( HTTP://計算器。com/questions/41461562/cast-to-objectid-failed-for-value-586cc8b3ea780c071bbe2469-at-path-id-for-m) –