无法使用和尚连接到远程服务器上托管的 mongodb [英] not able to connect to mongodb hosted on remote server using monk

查看:52
本文介绍了无法使用和尚连接到远程服务器上托管的 mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 node js,后端使用 mongodb

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

推荐答案

  1. 检查您的 IP 是否已列入白名单.
  2. 尝试通过 shell 连接

添加错误处理.

const db = require("monk")(uri);
db.then(() => {
  console.log('Connected correctly to server')
})

这篇关于无法使用和尚连接到远程服务器上托管的 mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆