最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

从共享的Linux托管服务器连接到mongodb Atlas时出错

IT培训 admin 4浏览 0评论

从共享的Linux托管服务器连接到mongodb Atlas时出错

我正在尝试从我的nodejs应用程序连接到mongoDB Atlas,这给了我以下错误:

SERVER STARTED...
listening on port 'http://localhost:8080'
Could not connect to the MongoDB database. Exiting now... { Error: connect ECONNREFUSED 13.234.134.161:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }

[我还在Mongodb Cloud(Atlas)上将IP列入了白名单。我将其设置为“所有人访问”,即:0.0.0.0/0

相同的代码在我的本地计算机上正常工作。

SERVER STARTED...
listening on port 'http://localhost:8080'
Successfully connected to the MongoDB database

当我将代码部署到GoDaddy共享linux托管服务器并尝试从那里连接时,会发生问题。

有什么不同...?

我的nodejs代码是:

app.set('port', process.env.PORT || 8080);

var options = {
    useNewUrlParser: true,
    useUnifiedTopology: true
}

mongoose.connect(dbConfig.dbUrl, options, function(err){
    if(err){
        console.log('Could not connect to the MongoDB database. Exiting now...', err);
        process.exit();
    } else {
        console.log("Successfully connected to the MongoDB database");
    }
});

const server = app.listen(app.get('port'), function(){
    console.log(`SERVER STARTED...\nlistening on port 'http://localhost:${app.get('port')}'`);
});

数据库URL如下:

dbUrl: "mongodb+srv://<USERNAME>:<PASSWORD>@cluster0-qsfll.mongodb/<DATABASE>?retryWrites=true&w=majority"

[如果有人遇到相同的问题并解决了,请在此处写下解决方案。谢谢:)。

回答如下:

刚刚遇到了同样的问题。尝试删除useUnifiedTopology。对我有帮助。

从共享的Linux托管服务器连接到mongodb Atlas时出错

我正在尝试从我的nodejs应用程序连接到mongoDB Atlas,这给了我以下错误:

SERVER STARTED...
listening on port 'http://localhost:8080'
Could not connect to the MongoDB database. Exiting now... { Error: connect ECONNREFUSED 13.234.134.161:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }

[我还在Mongodb Cloud(Atlas)上将IP列入了白名单。我将其设置为“所有人访问”,即:0.0.0.0/0

相同的代码在我的本地计算机上正常工作。

SERVER STARTED...
listening on port 'http://localhost:8080'
Successfully connected to the MongoDB database

当我将代码部署到GoDaddy共享linux托管服务器并尝试从那里连接时,会发生问题。

有什么不同...?

我的nodejs代码是:

app.set('port', process.env.PORT || 8080);

var options = {
    useNewUrlParser: true,
    useUnifiedTopology: true
}

mongoose.connect(dbConfig.dbUrl, options, function(err){
    if(err){
        console.log('Could not connect to the MongoDB database. Exiting now...', err);
        process.exit();
    } else {
        console.log("Successfully connected to the MongoDB database");
    }
});

const server = app.listen(app.get('port'), function(){
    console.log(`SERVER STARTED...\nlistening on port 'http://localhost:${app.get('port')}'`);
});

数据库URL如下:

dbUrl: "mongodb+srv://<USERNAME>:<PASSWORD>@cluster0-qsfll.mongodb/<DATABASE>?retryWrites=true&w=majority"

[如果有人遇到相同的问题并解决了,请在此处写下解决方案。谢谢:)。

回答如下:

刚刚遇到了同样的问题。尝试删除useUnifiedTopology。对我有帮助。

发布评论

评论列表 (0)

  1. 暂无评论