Pass option { useUnifiedTopology: true } to the MongoClient constructor Pass option { useUnifiedTopology: true } to the MongoClient constructor mongoose mongoose

Pass option { useUnifiedTopology: true } to the MongoClient constructor


You can do it this way

var mongoDb = require('mongodb');var mongoClient = mongoDb.MongoClient;var serverUrl = "mongodb://127.0.0.1:27017/";var dbName = "sample_db";mongoClient.connect(serverUrl, { useNewUrlParser: true, useUnifiedTopology: true }, function (err, db) {   // Code goes here...});


I'm using Mongoose for MongoDB, the same code with no error. mongoose.connect("mongodb://localhost:27017/YOURDB", { useNewUrlParser: true, useUnifiedTopology: true });


mongoose.connect('mongodb://localhost/vidly',{ useNewUrlParser: true , useUnifiedTopology: true }).then(()=>{ return console.log("Connected to MongoDB Localhost..."); }).catch(err => console.log("Could not connect",err))

It's working for me!!!