Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么猫鼬没有连接到MongoDB Atlas?_Mongodb_Mongoose - Fatal编程技术网

为什么猫鼬没有连接到MongoDB Atlas?

为什么猫鼬没有连接到MongoDB Atlas?,mongodb,mongoose,Mongodb,Mongoose,我正在尝试连接到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 { useUnifiedTopolog

我正在尝试连接到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)]: {} }
我在用, “猫鼬”:“^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)]: {} }
{MongoError:没有可用的mongos代理
超时。(/home/gaurav/Downloads/Assignments/DevConnection_2.0/node_modules/mongodb core/lib/topologies/mongos.js:736:28)
在ontimeout(timers.js:498:11)
在tryOnTimeout(timers.js:323:5)
在Timer.listOnTimeout(timers.js:290:5)中,名称:'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})            
        console.log("MongoDB Connected..")
} catch(err){
    console.error(err);
    process.exit(1);
}
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);
}
db=“mongodb+srv://:@devconnector-sk8na.mongodb.net/test?retryWrites=true&w=mailty”
试一试{
wait mongoose.connect(db,{useNewUrlParser:true,useUnifiedTopology:true})
console.log(“MongoDB已连接…”
}捕捉(错误){
控制台错误(err);
过程。退出(1);
}

这是否回答了您的问题?看看这个答案,没用!!我试图降级到猫鼬的旧版本,但它仍然无法连接。我收到错误“MongoError:没有可用的mongos代理”@shreyanzhain
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);
}