Closed nadim-khan closed 4 years ago
console.log("**"+'\n'+'\t'+" Server Started "+'\n'+"**"+'\n\n'); const express = require('express'); const router = express.Router(); const mongoose= require('mongoose'); const Video= require('../models/videos');
const db="mongodb://:@ds227654.mlab.com:27654/videos" mongoose.Promise=global.Promise;
mongoose.connect(db, function(err){ if(err){ console.log('ERROR ! '+'\n' + ' DB Error : '+err); } else{ console.log ('Connected to Database'); } })
//Testing api router.get('/',function(req,res){ res.send('Application Works'); });
router.get('/videos', function(req, res){ console.log('\n'+"Get request for all the videos "+'\n'); Video.find({}) .exec(function(err, videos){ if(err){ console.log('\n'+"Error retreiving Videos "+'\n'+"Error : "+err); } else{ res.json(); } }); });
module.exports = router;
I am getting the error
TypeError: Video.find is not a function
console.log("**"+'\n'+'\t'+" Server Started "+'\n'+"**"+'\n\n'); const express = require('express'); const router = express.Router(); const mongoose= require('mongoose'); const Video= require('../models/videos');
const db="mongodb://:@ds227654.mlab.com:27654/videos"
mongoose.Promise=global.Promise;
mongoose.connect(db, function(err){ if(err){ console.log('ERROR ! '+'\n' + ' DB Error : '+err); } else{ console.log ('Connected to Database'); } })
//Testing api router.get('/',function(req,res){ res.send('Application Works'); });
router.get('/videos', function(req, res){ console.log('\n'+"Get request for all the videos "+'\n'); Video.find({}) .exec(function(err, videos){ if(err){ console.log('\n'+"Error retreiving Videos "+'\n'+"Error : "+err); } else{ res.json(); } }); });
module.exports = router;
I am getting the error
TypeError: Video.find is not a function