Can't connect to a MongoDB using Node.js

Solution 1:

First make sure your MongoDB server is running by running mongod in the directory that MongoDB is installed.

Then see what port it is running on ( usually it's 27017 ) . Then update your URL in your code and you're good to go .

Solution 2:

Your error explaining itself. Mongo cant find default db path B:/data/db.

Create this folder or on start up choose another DB directory

mongod --dbpath yourPath(C:\myDb)

Also default mongo port is 27017 so you need to change connection string like this "mongodb://@localhost:27017/dbYouWant"

Hope this helps.