I am creating an express server in which I am trying to find the tracks in my database. Even though I have created the model to exactly how the attributes are in my database it still returns me an empty array. Please help
app.js
require('./config/config');
require('./db');
var Track = require('./models/track.model');
const mongoose = require('mongoose'),
express = require('express'),
bodyParser = require('body-parser');
var app = express();
const connection = mongoose.connection;
connection.once('open', () => {
console.log('MongoDB database connection established successfully!');
});
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.json());
app.get('/', function(req, res) {
Track.find({}, function(err, tracks) {
if (!err) {
console.log(tracks);
process.exit();
}
else {
throw err;
}
});
res.sendFile('index.html', {root: __dirname});
});
app.listen(process.env.PORT, ()=> console.log(`Server started at port: ${process.env.PORT}`));
track.model.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;
let Track = new Schema({
Position: {
type: Number
},
Track: {
type: String
},
Artist: {
type: String
},
Streams: {
type: Number
},
Url: {
type: String
},
Date: {
type: String
}
});
module.exports = mongoose.model('Track', Track);

mongoose.connect('mongodb://localhost/test', {useNewUrlParser: true});seems missing in your code.const mongoose = require('mongoose'); mongoose.connect(process.env.MONGODB_URI, {useNewUrlParser: true}, (err) => { if (!err) { console.log('MongoDB connection succeeded.'); } else { console.log('Error in MongoDB connection : ' + JSON.stringify(err, undefined, 2)); } });