I am uploading video details such as title, thumbnail, video file, and category to DB and displaying all thumbnails on the home page and while clicking on the thumbnail it will be forwarded to another page(watch video).
The home page is working fine with thumbnail, but when I click on the thumbnail it forwards to watch video page but it doesn't load the video path correctly but the title is displaying correctly. I am getting the following error while loading watch-video page. Help me to find the issue.
Error
Error: Argument passed in must be a single String of 12 bytes or a string of 24 hex characters
at new ObjectID (D:\Bitady\hakeek\node_modules\bson\lib\bson\objectid.js:59:11)
at ObjectID (D:\Bitady\hakeek\node_modules\bson\lib\bson\objectid.js:40:43)
at exports.getwatchVideo (D:\Bitady\hakeek\controllers\user.js:32:20)
at Layer.handle [as handle_request] (D:\Bitady\hakeek\node_modules\express\lib\router\layer.js:95:5)
at next (D:\Bitady\hakeek\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (D:\Bitady\hakeek\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (D:\Bitady\hakeek\node_modules\express\lib\router\layer.js:95:5)
at D:\Bitady\hakeek\node_modules\express\lib\router\index.js:281:22
at param (D:\Bitady\hakeek\node_modules\express\lib\router\index.js:354:14)
at param (D:\Bitady\hakeek\node_modules\express\lib\router\index.js:365:14)
at Function.process_params (D:\Bitady\hakeek\node_modules\express\lib\router\index.js:410:3)
at next (D:\Bitady\hakeek\node_modules\express\lib\router\index.js:275:10)
at Function.handle (D:\Bitady\hakeek\node_modules\express\lib\router\index.js:174:3)
at router (D:\Bitady\hakeek\node_modules\express\lib\router\index.js:47:12)
at Layer.handle [as handle_request] (D:\Bitady\hakeek\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (D:\Bitady\hakeek\node_modules\express\lib\router\index.js:317:13)
Routes in main.js
app.use('/admin', adminRoutes);
app.use(userRoutes);
app.use(authRoutes);
Routes - user.js
router.get('/about', userController.getAbout);
router.get('/watch-video/:videoId', userController.getwatchVideo);
router.get('/', userController.getVideos);
watch-video - Controller
exports.getwatchVideo = (req, res, next) => {
const id = req.params.videoId;
const videoID = ObjectId(req.params.videoId);
//console.log(videoID);
//console.log(id);
//const videoID = req.params.videoId;
//Video.findOne({_id: videoID})
Video.findById(id)
.then(videoFile => {
if(!videoFile){
return console.log('Video not found');
}
console.log(videoFile);
res.render('user/watch', {
wvideoData: videoFile,
pageTitle: videoFile.title,
path: 'watch-video'
});
})
.catch(err => {
console.log(err);
});
};
User Home page
Recent Uploads
<% for (let items of videos) { %><%= items.title %>
<%= items.title %>