mongodb - 无法连接到 mongoDB 图集
问题描述
我已经正确安装了所有东西,但不知道发生了什么。这是代码
// 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 代码中的错误是 - 错误:QueryReqWrap.onresolve
处的 queryTxt ETIMEOUT blogging-site.mantx.mongodb.net [as oncomplete] (dns.js:203:19) { errno: undefined, code: 'ETIMEOUT',系统调用:'queryTxt',主机名:'blogging-site.mantx.mongodb.net'} 我正在关注网络忍者教程,希望我没有按照他的指示离开任何步骤。我之前使用过 mongoDB atlas 并在我的计算机上安装了 mongodb。这会产生任何问题吗?
解决方案
没有问题,因为“我可以连接”到它。
我可以连接到它
我,一个你不认识的人,一个很可能在世界另一端的人
可能是一个怀有恶意的人(尽管我不是)。
这可能是连接问题(由于互联网不好或其他原因),但更大的问题是
我可以连接到它
因此,也许您希望在将 MongoDB URI 部分公开以供所有人查看之前将其保留,除非您希望邪恶的人从您的数据库中窃取用户信息、会话数据以及其他内容。
快乐学习!!!
评论后编辑 以下是开始使用猫鼬时应该学习的内容:
-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 变量中的字符串是连接到数据库图集的一种方式。你把它给了我,我使用它并连接到它。
推荐阅读
- azure-logic-apps - 在逻辑应用程序中创建 Microsoft 表单触发器时,我只能看到我创建的表单
- python - 使用 Selenium 登录后使用 Pandas 和 Beautiful Soup 从表中收集数据
- javascript - 调用函数等待完成从 javascript 到 html 函数的事情的困难
- flutter - Flutter 类型“null”不是“string”类型的子类型
- python - 在 Python 中使用 PyYAML 创建 yaml 流集合
- java - How can I use an icon for a conditional in Java?
- amazon-web-services - AWS 负载均衡器将 :80 附加到 http 上的 url 到 https 301 重定向
- active-directory - 为什么客户总是希望通过 AD 和使用 AD 安全组的安全创建用户帐户?
- visual-studio - 我无法调试 Xamarin.Android 应用程序
- javascript - 在 redux 中调度存储变量时,React 组件不会重新渲染