MongoDB stopped working suddenly after days of development - node.js

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.

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

Mongo Compass Can't Connect to my Server. NodeJS and shell works

I have a MongoDb server setup on my server.
When i start my nodeJs application on it it works perfectly, i can also view and edit my db using the shell when im connected via ssh.
It also used to work with mongo Compass, then a few days suddenly i couldn't connect to my db using compass anymore. Shell and nodeJs connections are still working tho.
I Am getting The Error connect ECONNREFUSED 127.0.0.1:27017
After a Bit looking around an i read a article stating i should look at the log at /var/log/mongodb/mongobd.log
This is The Output from The log, when im trying to connect via ssh. I've already confirmed that this entry is mongo compass trying to connect by restarting and shutting down every service which is using mongodb.
2020-05-03T21:26:19.575+0000 I NETWORK [listener] connection accepted from 127.0.0.1:33694 #5 (3 connections now open)
2020-05-03T21:26:49.689+0000 I NETWORK [conn5] end connection 127.0.0.1:33694 (2 connections now open)

Docker compose/nodejs: Restart required to connect after ECONNREFUSED

I have a docker-compose file. There is a mysql service and a nodejs service (Nestjs using TypeORM). Sometimes when I bring the stack up, the nestjs service tries to connect to the mysql service before it is ready, and gives me a ECONNREFUSED. I've set it up to retry connecting more or less indefinitely, but once mysql is up, it continues to give me the ECONNREFUSED error.
While it is retrying, and once mysql is up, I can connect to the mysql service using nc mysql 3306, confirming it indeed can. But for some reason I continue to get the ECONNREFUSED error. Once I restart the nodejs service it connects properly. The closest I've come to figuring out the problem is perhaps it has something to do with a Connection Pool that is created in the typeorm package. Any idea how I can deal with this?`

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.

connect ECONNREFUSED 127.0.0.1 in node.js

so I make a server in nodejs to connect with mongodb, from the start I use it until tomorrow is working fine, but today when I use it there is this error
this error appear when user want log in in my application.

Resources