Solvedmongoose 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.

Hi, I just downloaded latest version of mongoose from npm and tried to run it but it gave me this warning:
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.

i added this option to my configuration but it still gives me this warning. here is my configuration

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useFindAndModify: false, useCreateIndex: true, useUnifiedTopology: true }).then(()=>{ console.log(connection to database established) }).catch(err=>{ console.log(db error ${err.message}); process.exit(-1) })

any clue?

21 Answers

✔️Accepted Answer

This works fine for me, and no more errors.

mongoose
.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log(DB Connection Error: ${err.message});
});

Other Answers:

It still error:

const options = {
    keepAlive: 1,
    useUnifiedTopology: true,
    useNewUrlParser: true,
  };
  mongoose.connect(dbUrl, options).then(() => console.log('DB connected'));

It output:

(node:14923) 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.

Anyone can help me? Thanks!