I'm working on a rest api that will get premade data from mongodb, but for some reason it is not getting data that is already in mongodb. When I type in localhost:3000/film, it doesn't return any data at all. It returns [ ] and that's it. I have checked mongodb and the data is already there.
the commands i used are:
mongo
use FilmTest
show collections
db.Film.find()
It return all the data that is in it in json format, so the test data is already there but the rest api isn't returning it when I look in /film when starting up the node server.js
server.js
var express = require('express');
var mongoose = require('mongoose');
var cors = require('cors');
mongoose.connect('mongodb://localhost:27017/FilmTest')
var filmSchema = ({
categoryId: String,
genre: String,
title: String,
releaseDate: String,
rating: Number,
director: String,
cast: String,
production: String,
description: String,
plot: String,
opinion: String,
isSpecial: String,
imageS: String,
imageL: String
});
var Film = mongoose.model('Film', filmSchema, 'film')
var app = express()
app.use(cors());
app.get('/film', function(req, res) {
Film.find(function (err, doc) {
res.send(doc);
})
})
app.listen(3000);