0

I am trying to connect to MongoDB Atlas But I am getting this error

(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",

Even if I downgrade to Mongoose version 5.6.13, Deprecation warning goes away but still the following error persists -

{ 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)]: {} }
  • Does this answer your question? [Server Discovery And Monitoring engine is deprecated](https://stackoverflow.com/questions/57895175/server-discovery-and-monitoring-engine-is-deprecated) – Shreyansh Jain Dec 15 '19 at 16:58
  • https://stackoverflow.com/questions/57895175/server-discovery-and-monitoring-engine-is-deprecated/57899638#57899638 look at this answer – Shreyansh Jain Dec 15 '19 at 16:58
  • Not working!! I tried to downgrade to older versions of mongoose but still it is not getting connected. I am getting the error 'MongoError: no mongos proxy available' @ShreyanshJain – Gaurav Sharma Dec 15 '19 at 17:27

1 Answers1

0

Without downgrading,

Can you add this line next to useNewUrlParser:true and then run again?

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);
}
Sandun
  • 395
  • 2
  • 10
  • 25