mongodb - 为什么猫鼬没有连接到 MongoDB Atlas?
问题描述
我正在尝试连接到 MongoDB Atlas 但我收到此错误
(node:7191) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
{ MongoError: no mongos proxy available
at Timeout.<anonymous> (/home/gaurav/Downloads/Assignments/DevConnection_2.0/node_modules/mongoose/node_modules/mongodb/lib/core/topologies/mongos.js:739:28)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }
我正在尝试像这样连接
db = "mongodb+srv://<username>:<password>@devconnector-sk8na.mongodb.net/test?retryWrites=true&w=majority"
try{
await mongoose.connect(db, { useNewUrlParser: true})
console.log("MongoDB Connected..")
} catch(err){
console.error(err);
process.exit(1);
}
我还在使用时替换了用户名和密码。
我应该得到这个输出 -
MongoDB connected...
我正在使用,“猫鼬”:“^5.8.1”,
即使我降级到 Mongoose 版本 5.6.13,弃用警告也会消失,但以下错误仍然存在 -
{ MongoError: no mongos proxy available
at Timeout.<anonymous> (/home/gaurav/Downloads/Assignments/DevConnection_2.0/node_modules/mongodb-core/lib/topologies/mongos.js:736:28)
at ontimeout (timers.js:498:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }
解决方案
无需降级,
您可以在旁边添加此行useNewUrlParser:true
然后再次运行吗?
useUnifiedTopology: true
您的代码应如下所示
db = "mongodb+srv://<username>:<password>@devconnector-sk8na.mongodb.net/test?retryWrites=true&w=majority"
try{
await mongoose.connect(db, { useNewUrlParser: true, useUnifiedTopology: true })
console.log("MongoDB Connected..")
} catch(err){
console.error(err);
process.exit(1);
}
推荐阅读
- jquery - 附加到最接近的 - 对于每个:重复的模式
- nested - Bootstrap flex 嵌套行并排定位,而不是一个在另一个下
- google-cloud-ml - 在 AI Platform 中部署 PyTorch 模型
- java - 如何在外部 Tomcat 服务器中运行 WAR 文件的设置代码
- ios - 为什么我的 @State 对象不保留其价值?
- python - Pandas 用 1 替换数据帧的所有非 NaN 条目,不理会 NaN
- cookies - 将 cookie 添加到 GET 请求未显示
- javascript - 在其他组件中渲染组件的一部分
- c++ - 2 个管道写入同一个子进程的 STDIN
- artifactory - jfrog artifactory 无法验证路由器错误