【问题标题】:Error in connecting node.js app to mongoDb Atlas database将 node.js 应用程序连接到 mongoDb Atlas 数据库时出错
【发布时间】:2020-11-08 19:35:01
【问题描述】:

当我尝试将我的 node.js 应用程序与我创建了一个名为 test 的数据库的 mongodb atlas 连接时,我在控制台中收到以下错误。

Error: queryTxt ETIMEOUT cluster0.z7ysr.mongodb.netat QueryReqWrap.onresolve [as oncomplete]

我有一个免费的 atlas 帐户。 我在项目中使用了 mongoose 库和以下代码。

mongoose.connect('mongodb+srv://username:pwd@cluster0.z7ysr.mongodb.net/testretryWrites=true&w=majority'
{
    useNewUrlParser: true,
    useUnifiedTopology: true
});

【问题讨论】:

  • 嘿@nikunjkr,只是确认一下,您是故意将用户名:pwd 保留为用户名:pwd 还是您没有编辑的内容。
  • 嗨! @AshutoshKumar 我刚刚将原来的用户名和密码分别更改为用户名和密码。
  • 请显示更多代码。
  • 好的,谢谢stackoverflow.com/questions/61800062/… 是否解决了这个问题。
  • 查看@NithinKJoy 的答案,逗号似乎可以解决它

标签: node.js mongodb mongoose mongodb-atlas


【解决方案1】:

使用,(逗号)。你在 Mongo URI 字符串后面漏掉了一个逗号。

let db='mongodb+srv://username:pwd@cluster0.z7ysr.mongodb.net/testretryWrites=true&w=majority'
//Used comma below.
mongoose.connect(db,{
    useNewUrlParser: true,
    useUnifiedTopology: true
});

【讨论】:

  • 哦,太好了!!
  • 哦,你错过了。谢谢@NithinKJoy :)
  • 欢迎兄弟。 :) 将我的答案标记为正确,这样我的答案也可能对其他人有所帮助。
  • @nikunjkr,如果解决了,请将其标记为最佳答案,然后可能关闭问题。
猜你喜欢
  • 2021-10-02
  • 2022-01-18
  • 2020-01-12
  • 2020-09-18
  • 2021-11-09
  • 1970-01-01
  • 2020-09-27
  • 2020-10-12
  • 2019-04-29
相关资源
最近更新 更多