Jump to content

Nodejs - error in a code


yearmfew

Recommended Posts

I am currently working mongodb and nodejs from w3schools website. I have seen an error in a code. 

https://www.w3schools.com/nodejs/nodejs_mongodb_create_db.asp

In this website there is a code for creating website. : 

var MongoClient = require('mongodb').MongoClient;
var url = "mongodb://localhost:27017/mydb";

MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  console.log("Database created!");
  db.close();
});

When I run this, I see this on the terminal: 

(node:26812) 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.
Database created!

 

I needed to change 3rd line. 

old 3rd line: 

MongoClient.connect(url, function(err, db) {

new 3rd line: 

MongoClient.connect(url, {useUnifiedTopology: true}, function(err, db) {

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...