Jump to content
Sign in to follow this  
yearmfew

Nodejs - error in a code

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) {

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...