[英]Not able to connect to mongoDB atlas
我已经正确安装了所有东西,但不知道发生了什么。 这是代码
// Connect to MongoDB
const dbURI = 'mongodb+srv://<username>:<password>@blogging-site.mantx.mongodb.net/Blogging-site?retryWrites=true&w=majority';
try {
// Connect to the MongoDB cluster
mongoose.connect(dbURI,{ useNewUrlParser: true, useUnifiedTopology: true },
() => console.log(" Mongoose is connected")
);
} catch (e) {
console.log("could not connect");
}
我的 VS 代码 treminal 中的错误是 - 错误:queryTxt ETIMEOUT blogging-site.mantx.mongodb.net
在 QueryReqWrap.onresolve [as oncomplete] (dns.js:203:19) { errno: undefined, code: 'ETIMEOUT', syscall: 'queryTxt', hostname: 'blogging-site.mantx.mongodb.net' } 我是遵循网络忍者教程,希望我没有按照他的指示离开任何步骤。 我之前使用过 mongoDB 地图集,并在我的计算机中安装了 mongodb。 这会产生什么问题吗?
没有问题,因为“我可以连接”到它。
我可以连接到它
我,一个你不认识的人,一个很可能在世界另一端的人
可能是一个怀有恶意的人(尽管我不是)。
这可能是连接问题(由于互联网不好或其他原因),但更大的问题是
我可以连接到它
因此,也许您希望在将 MongoDB URI 部分公开以供所有人查看之前将其保留,除非您想要一个邪恶的人窃取用户信息、session 数据,以及您的数据库中没有的数据。
快乐学习!!!
在评论后编辑以下是您在 mongoose 中应该学习的内容:
-setting up initial(also called default) connection with mongoose.connect()
-configuring schemas with mongoose.Schema()
-compiling models with schemas with mongoose.model()
-saving the doc with mongoose.save()
-querying the database(findOne, find, deleteOne, updateOne, findById are the
ones I find most used)
也许当你习惯了所有这些时,你可以开始学习填充(你可能会在更大的项目中需要它)、创建多个连接和导出模式模式、验证、mongooseJs 的中间件等等,我确信你会自己调查的。
至于“你能告诉我你是如何连接到地图集的吗?” :
我刚刚复制了您的代码并在我的计算机上运行。 就那么简单。 dbURI 变量中的字符串是连接到数据库图集的一种方式。 你把它给了我,我使用它并连接到它。
Error: queryTxt ETIMEOUT
当客户端尝试从 DNS 检索blogging-site.mantx.mongodb.net
的 TXT 记录时,它超时。
在同一台机器上,使用 nslookup 进行测试以检索 TXT 记录,如果您的 DNS 提供程序不支持,您将需要使用非 SRV 连接字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.