0

I am getting error while trying to connect Mongodb and Nodejs on local server please any one help me with this problem

my JavaScript code

const mongodb = require("mongodb");

//provide the function sto connect to database
const MongoClient = mongodb.MongoClient;
const connectionURL = "mongodb://120.0.0.1:2701"
const databaseName = "task-manager"

MongoClient.connect(connectionURL,{useNewUrlParser:true},(error,client)=>{
if(error){
    return console.log(error)
}

console.log("connected to database")
})

here is the screenshot of error which I am facing

2 Answers 2

1

Replace your code with this code:

const connectionURL = “mongodb://120.0.0.1:27017”;

And add useUnifiedTopology:true with useNewUrlParser:true

Sign up to request clarification or add additional context in comments.

Comments

0

The error says "connection time out", what means either your server is very slow or there is no mongoDB at the specified ip%port. If I assume that correctly that your mongoDB is running on localhost, that you have an typo in your connectionURL.You set it to 120.0.0.1. It should probably be 127.0.0.1.

const connectionURL = "mongodb://127.0.0.1:2701" or const connectionURL = "mongodb://localhost:2701"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.