Warning on Connecting to MongoDB with a Node server Warning on Connecting to MongoDB with a Node server mongoose mongoose

Warning on Connecting to MongoDB with a Node server


Check your mongo version

 mongo --version

If you are using version >= 3.1.0 change you mongo connection file to ->

 MongoClient.connect("mongodb://localhost:27017/YourDB", {   useNewUrlParser: true,   useUnifiedTopology: true })

For details about the useUnifiedTopology option added in 3.2.1, see https://github.com/mongodb/node-mongodb-native/releases/tag/v3.2.1


My advice is to leave it as it is (maybe place a warning). The useUnifiedTopology: true option does not work correctly.

More precisely, in the event of a loss of connection to the DBMS, it will never be restored. Current version 3.3.3 does not solve this problem.

Check this


I got the same error and resolved using the below template.

var MongoClient = require('mongodb').MongoClientconst client = new MongoClient(uri, {useUnifiedTopology: true});client.connect().then((client)=>{    var db = client.db('db_name')    db.collection('collection_name').find().toArray(function (err, result) {        if (err) throw err        console.log(result);    })})

This worked for me. and now it's not showing any DepricationWarning.