Issue Connecting to MongoDB collections Issue Connecting to MongoDB collections mongoose mongoose

Issue Connecting to MongoDB collections


Are you setting any access controls in the code?

Also refer to mongoDB's documentation here:https://docs.mongodb.com/manual/core/collection-level-access-control/


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');        }    });}