首页 > 解决方案 > 错误:querySrv ESERVFAIL _mongodb._tcp.cluster0.abcd0.mongodb.net

问题描述

我的 nodejs 应用程序在 mongodb 连接上运行良好,突然出现了这个错误。然后我尝试使用 mongo compass 连接到 mongodb 并且存在同样的错误。我找不到任何原因。

Error: querySrv ESERVFAIL _mongodb._tcp.cluster0.abcd0.mongodb.net
[nodemon] app crashed - waiting for file changes before starting...

然后我将 mongodb 连接 url 更改为旧 url,之后我得到了这个错误。

Error: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
[nodemon] app crashed - waiting for file changes before starting...

我已经将我的 ips 列入白名单并且我的配置是正确的(我仔细检查了)。0.0.0.0/0(包括您当前的 IP 地址)

这是什么原因?

谢谢你。

标签: mongodbmongoosemongodb-atlas

解决方案


querySrv ESERVFAIL是 DNS 错误。

这意味着您的本地计算机无法从您的 DNS 解析器获得对 SRV 记录的响应_mongodb._tcp.cluster0.abcd0.mongodb.net (我假设这不是您的真实主机名,但它可以作为示例)

在您的本地计算机上,从命令行测试 SRV 查找,可能是以下之一:

nslookup -type=SRV _mongodb._tcp.cluster0.abcd0.mongodb.net
host -t SRV _mongodb._tcp.cluster0.abcd0.mongodb.net

如果失败,请随意对您的 DNS 提供商说坏话。

然后转到 Atlas UI 并获取 3.6 之前的连接字符串。它将以mongodb://and not开头mongodb+srv://


推荐阅读