I am using Mongoose with my Node.js app and this is my configuration:
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
useFindAndModify: false
}).then(()=>{
console.log(`connection to database established`)
}).catch(err=>{
console.log(`db error ${err.message}`);
process.exit(-1)
})
but in the console it still gives me the 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.
What is the problem? I was not using useUnifiedTopology
before but now it shows up in the console. I added it to the config but it still gives me this warning, why? I do not even use MongoClient
.
Edit
As Felipe Plets answered there was a problem in Mongoose and they fixed this bug in later versions. So you can solve problem by updating mongoose version.
This works for me!
This will solve three DeprecationWarning
Hope it helps.
This worked for me
For folks using
MongoClient
try this:For mongoose:
Remove other connectionOptions
I was also facing the same issue:
I made sure to be connected to mongoDB by running the following on the terminal:
And I got the output:
Instructions for installing mongodb at
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/ or https://www.youtube.com/watch?v=IGIcrMTtjoU
My configuration was as follows:
Which solved my problem!
In mongoDB, they deprecated current server and engine monitoring package, so you need to use new server and engine monitoring package. So you just use
I want to add to this thread that it may also have to do with other dependencies.
For instance, nothing I updated or set for NodeJS, MongoDB or Mongoose were the issue - however -
connect-mongodb-session
had been updated and starting slinging the same error. The solution, in this case, was to simply rollback the version ofconnect-mongodb-session
from version2.3.0
to2.2.0
.