[英]Why mongoose is not connecting to MongoDB Atlas?
I am trying to connect to MongoDB Atlas But I am getting this error我正在尝试连接到 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)]: {} }
I am trying to connect like this我正在尝试像这样连接
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);
}
I also replaced username and password while using it.我也在使用它时更换了用户名和密码。
I should get this output -我应该得到这个输出 -
MongoDB connected...
I am using, "mongoose": "^5.8.1",我正在使用,“猫鼬”:“^5.8.1”,
Even if I downgrade to Mongoose version 5.6.13, Deprecation warning goes away but still the following error persists -即使我降级到 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)]: {} }
Without downgrading ,不降级,
Can you add this line next to useNewUrlParser:true
and then run again?您可以在
useNewUrlParser:true
旁边添加这一行,然后再次运行吗?
useUnifiedTopology: true
Your code should look like this你的代码应该是这样的
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.