I am using node js, and for the backend i am using mongodb
For connecting to DB, if i use the below line, it is fetching data
var db = monk('localhost:27017/nodetest2');
But if i change that to below line, its not fetching the data
var db = monk('mongodb://username:password@XXX.mongolab.com:27483/userdb');
I have created the collection with same name in both places
router.get('/userlist', function (req, res) {
var db = req.db;
var collection = db.get('userlist');
collection.find({}, {}, function (e, docs) {
res.json(docs);
});
});
来源:https://stackoverflow.com/questions/31668288/not-able-to-connect-to-mongodb-hosted-on-remote-server-using-monk