Issue Connecting to MongoDB collections
Here is my solution:In your app.js, have this:
let mongoose = require('mongoose');mongoose.connect('Your/Database/Url', { keepAlive : true, reconnectTries: 2, useMongoClient: true});
In your route have this:
let mongoose = require('mongoose');let db = mongoose.connection;fetchAndSendDatabase('yourCollectionName', db);function fetchAndSendDatabase(dbName, db) { db.collection(dbName).find({}).toArray(function(err, result) { if( err ) { console.log("couldn't get database items. " + err); } else { console.log('Database received successfully'); } });}