我正在尝试将我的mongoose连接到MongoDB Atlas集群。目前它没有任何数据库,但每当我尝试时:
mongoose.connect( uri || 'mongodb://localhost/test',options)
.then(()=>{
console.log("Connected to the Database. Yayzow!");
})
.catch(err => {
console.log(err);
});
我收到了这条消息:
Error: queryTxt ETIMEOUT cluster0-ghis2.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:202:19) {
errno: 'ETIMEOUT',
code: 'ETIMEOUT',
syscall: 'queryTxt',
hostname: 'cluster0-ghis2.mongodb.net'
}
我的依赖:
"dependencies": {
"express": "^4.17.1",
"mongodb": "^3.5.7",
"mongoose": "^5.9.14"
}
目前我已将所有IP地址加入白名单(0.0.0.0/0)。同时,我确保我的防火墙和杀毒软件都已断开。我还让朋友来检查过,他可以使用,但我却不能。
感谢任何帮助!
编辑
通过更改DNS为Google的Public DNS解决了错误!如果有人遇到此错误,请确保更改您的DNS。在这里提供一个链接here