node.js - MongoDB Atlas 连接在 Heroku for NodeJS 上不起作用
问题描述
我在 Heroku 上不断收到此错误:
UnhandledPromiseRejectionWarning: MongooseServerSelectionError: 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/
我已经将 0.0.0.0 和我自己的 IP 地址添加到 Atlas。
这就是我连接的方式(使用猫鼬):
// link mongoose
mongoose.connect(process.env.DB_LINK, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});
我已经将 DB_LINK 添加到 Heroku 上的配置变量中。
一切都在本地主机上运行良好。我不确定为什么这不起作用。最后我也收到此错误:
at=error code=H12 desc="Request timeout"
感谢您的帮助!
解决方案
推荐阅读
- jquery - 如何在 Angular 2+ 中使用循环和自动播放轮播
- json - Postman 无法处理长字符串的 JSON 响应
- html - 两种类型属性“按钮”和“提交”合二为一
- javascript - JS如何将childs方法引用到父构造函数ES6类
- c - 当我尝试索引除零以外的任何内容时,指向索引超出范围的结构指针的指针(?)
- javascript - 如果提交,确认电子邮件不会删除验证消息,但表单的其他元素需要完成
- ios - 在应用升级时从 iOS 的设置屏幕中删除设置
- machine-learning - 预测神经网络中的输入
- html - type="submit" 是 IE8 到 11 中表单中按钮的默认值吗?
- data-structures - 实现链表构造函数以将值填充到特定大小