not able to connect to mongodb hosted on remote server using monk

倾然丶 夕夏残阳落幕 提交于 2020-01-02 12:23:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!