簡體   English   中英

為什么貓鼬沒有連接到 MongoDB Atlas?

[英]Why mongoose is not connecting to 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);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM