我无法从共享主机连接到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);
});
这是我得到的错误:
错误,连接到数据库!:无法连接到服务器[test-shard-00-00-nhowr.mongodb.net:27017]在第一次连接时[MongoNetworkError:连接ECONNREFUSED 54.172.133.240:27017
请替换为真实的凭据。
[如果您不知道如何,只需转到左侧菜单中的Atlas帐户,找到“安全性”>“数据库访问”>单击“添加新用户”并创建用户名和密码,然后将其替换为占位符。