Node.js 从共享主机连接到mongodb Atlas时出错

Node.js 从共享主机连接到mongodb Atlas时出错,node.js,mongodb,port,atlas,Node.js,Mongodb,Port,Atlas,我无法从共享主机连接到mongodb Atlas,据我所知,这是因为27017端口被防火墙阻止。 有没有办法更改mongodb Atlas上的端口号 这是我的nodejs文件中的代码: mongoose.connect("mongodb+srv://<username>:<password>@test-nhowr.mongodb.net/test?retryWrites=true&w=majority", { useNewUrlParser: tru

我无法从共享主机连接到mongodb Atlas,据我所知,这是因为27017端口被防火墙阻止。 有没有办法更改mongodb Atlas上的端口号

这是我的nodejs文件中的代码:

 mongoose.connect("mongodb+srv://<username>:<password>@test-nhowr.mongodb.net/test?retryWrites=true&w=majority", {
      useNewUrlParser: true,
      useCreateIndex: true,
    }).then(() => {
      console.log("Connected to DB");
    }).catch(err => {
      console.log('ERROR Connecting to db!: ', err.message);
    });
mongoose.connect(“mongodb+srv://:@test-nhowr.mongodb.net/test?retryWrites=true&w=mailty”{
useNewUrlParser:true,
useCreateIndex:true,
}).然后(()=>{
console.log(“连接到数据库”);
}).catch(错误=>{
console.log('连接到数据库时出错!:',错误消息);
});
这就是我得到的错误:

连接到数据库时出错!:无法连接到服务器 第一次连接时[test-shard-00-00-nhowr.mongodb.net:27017] [MongoNetworkError:connect-EconRefuse54.172.133.240:27017


请用真实凭证替换和


如果您不知道如何操作,只需转到左侧菜单中的atlas帐户,查找安全>数据库访问>单击“添加新用户”创建一个用户名和密码,然后用占位符替换它。

我的应用程序中有正确的用户名和密码。我只是在这里发布时将其更改为私有。我设法使用完全相同的代码从aws cloud9登录,但端口27017被防火墙阻止。我只想知道如何更改端口,而不是default,即27017。谢谢!Atlas使用白名单访问。请确保您的IP地址在Atlas中被白名单。如果主机IP地址由网络层转换,请确保使用Atlas看到的IP地址。无法更改Atlas使用的端口。如果您当前的主机阻止您连接到27017,则您应该转移到另一个provider为您提供灵活性,满足您的需求。