My app works locally, but in production I can't seem to fetch a specific thing from mongo using mongoose. I've tried:
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)){})
I've received the same error:
Cast to ObjectId failed for value "586bc06bd09d870012baa5b8" at path "_id" for model "Coach"
Like I said, it works locally with both nodemon
and heroku local
but on my heroku production server it doesn't work.
I've read a little about this type of cast error here:
- 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"
But no luck yet. Any help would be great. Thank you in advance.