MongoDB no connection could be made because the target machine actively refused it - node.js

I was connecting to my MongoDB database installed on my local pc, everything was working fine i was ble to work with mongodb collections when suddenly my pc shutdowned because of loadshedding. After I turned it on again everything was fine except my Mongo Db connection was refused. This was the message being displayed:
cmd mongodb connection error
I think this is caused by firewall, what else it can be? Please help!

Okay so I was able to solve my problem. There was an issue with database path. I don't know why this problem arised because I had worked with this db before my pc went off.
However I was able to resolve this issue:
First locate the directory where your db's are stored. Then in your CLI whichever you are using:
<Your mongodb/server/bin directory>: mongod --dbpath "<your db directory>"

Related

Unable to connect ECONNREFUSED / Unable to connect ENOTFOUND mongo db vsCode

I'm trying to connect my mongodb to my vscode and when I try and connect to it using 'mongodb:// it comes up with a connection error. Can anyone help me with this please? 1
you need to try this flow to solve your issue. might be it helps you.
check mongo service is running or not.
if you mongo service is out side of your current machine than you check your IP has access to access your mongo service
check your mongo connection URL is correct.
try to connect your MongoDB using tools like MongoCompass or Robo 3t.
then try in your code for further task

MongoDB stopped working suddenly after days of development

After a few days of developing using Nodejs and MongoDB today I'm getting this error when I want to get into the first page of my app:
MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
And when I try to connect to db using mongodb compass:
Have you verified if mongo is running in the background?
Run mongod in the terminal and see the response, maybe your mongo process is'nt running and then you cant connect to your local mongodb.
I had the same issue and I fixed it.
Go to Services -> search for "MongoDB Server".
Right Click on it and then Click on Start.

Router cannot connect to MongoDB cluster

I am working on a MERN project. I was previously able to connect to the MongoDB cluster via the connection string in my node application. A few days ago I changed my wifi router and I am not able to connect to the database anymore.
I am sure the problem is the router because when I connect through my phone's internet, the connection is successful. Unfortunately, I cannot use my phone's internet always as it is really expensive.
I have tried to factory reset my router as suggested in this question.
Error at connecting to MongoDb Atlas Server
I have also tried to enable port forwarding for port 27017, 27018, 27019 (default ports of MongoDB) through the router settings as suggested by someone on the internet.
Screenshot of my router settings
But did not face any success.
Some additional information. I am using a d-link router(DIR-819). The latest version of windows, node.js at the time of asking this question. Any help would be greatly appreciated as I am stuck on this problem for hours now.
EDIT: Here is the output when I try connecting through the shell.
DNSHostNotFound: Failed to lookup service ": This operation returned because the timeout period expired.
try 'mongo --help' for more information.
Please help me out, guys.
I have whitelisted all the IP addresses.
Cheers Everyone
Okay, look I'm also facing the same issue.
The reason behind this is because your Router is not letting your backend to make a connection with the MongoDB atlas.
You can still use it through your mobile network. Connect your PC with your mobile network and then try again it will work. (worked for me)
And for the Router issue, I'm still searching the solution once I find it, I'll be updating the answer. And yes if you find the solution before me be sure to Update us.
Use MongoDB in local machine. If that helps. I was also facing a similar issue so dropped the idea of connecting it to MongoDB Atlas. I downloaded it and it's running smoothly
Try to downgrade nodejs driver. I have resolved this by downgrading nodejs 3.2 driver string to 2.2 driver string.

queryTxt ETIMEOUT merncluster-0jdze.mongodb.net

I'm using nodejs with MongoDB server using mongoose, whenever I try to run my server, it won't connect to my database. After sometime above log is seen on CMD. My cluster name is merncluster here!!
Is there any solution to this, I've searched a lot, still can't find proper solution to this, this keeps happening all the time.
You may need to whitelist your IP address in MongoDB Atlas.
Adding 8.8.8.8 to my connection to the internet works for me.

Connecting to a mongoDB with a TCP prefix on a NodeJS application

I created a NodeJS app that connects with a MongoDB and it seems to work locally.
Now, after hosting the NodeJS application on a remote machine, I am trying to connect to a mongoDB that was already created on that machine. When I print out some of the environment variables, the only one I see of relevance seems to be :
MONGODB_PORT: 'tcp://172.30.204.90:27017',
I tried connecting like I usually do with
mongoose.connect('mongodb://localhost:27017/metadata/')
and replacing it with mongoose.connect('tcp://172.30.204.90:27017/metadata') but I get an error that says my URI needs to start with 'mongodb'.
So I tried replacing it with mongoose.connect('mongodb://172.30.204.90:27017/metadata') and it no longer throws any error. But on the MongoDB side I don't see any new connections happening and my app does not start up on the machine. What should I be putting in the URI?
Your URI should indeed start with mongodb:
mongoose.connect('mongodb://username:password#host:port/database?options...');
See this page for more information: https://docs.mongodb.com/manual/reference/connection-string/
Did you try to connect to the database from cli? Or Telnet to see that connection isn't blocked.

Resources