MongoLab - How to resolve ECONNREFUSED - node.js

I have a NodeJS application using MongoDB as the database. I'm using mongoose for mongodb related activities.
I have an account in MongoLab and I use that for my database related activities of my application.
When trying to connect to MongoLab as below from nodejs
mongoose.connect("<db_url_with_username_password>", function(err) {
if(err)
{
console.log("Error is "+err);
throw err;
}
});
It's logging the following line
Error is MongoError: connect ECONNREFUSED 54.161.65.217:19058
I thought the server could be down, hence I checked the website online, it's working perfectly.
I pinged the server with the following
ping 54.161.65.217
and it's working fine.
64 bytes from 54.161.65.217: icmp_seq=0 ttl=28 time=271.396 ms
64 bytes from 54.161.65.217: icmp_seq=1 ttl=28 time=268.824 ms
However, When I'm trying to connect using the mongo command to connect, it's failing
mongo 54.161.65.217:19058/<db_name> -u <username> -p <password>
MongoDB shell version: 3.2.1
connecting to: 54.161.65.217:19058/arogyavath
2016-03-14T10:28:27.200+0530 W NETWORK [thread1] Failed to connect to 54.161.65.217:19058, reason: errno:61 Connection refused
2016-03-14T10:28:27.201+0530 E QUERY [thread1] Error: couldn't connect to server 54.161.65.217:19058, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
I looked around and found the following questions which could be similar to mine
Node.js Error: connect ECONNREFUSED
ECONNREFUSED error when connecting to mongodb from node.js
But the answers I found there didn't help me fix the issue.
Could the server ip address be blocked from my network or something? How do I fix this?
I would be very glad if someone can point me in the right direction. Thanks in Advance.

Related

Unable to connect mongoDB server with my node.js file, getting MongooseServerSelectionError: connect ECONNREFUSED ::1:27017 constantly

mongod database process running
Local server connected to mongoDB compass
created mongooseTut Folder
npm init
mongoose and node installed
when i try to connect to server by writing node .\index.js, it thorws the error shown in picture, i.e.-MongooseServerSelectionError: connect ECONNREFUSED ::1:27017
P.S.: Have already tried each and every solution mentioned in all relevant replies on stackoverflow.
Tried connecting node.js to mongoDb server and got error MongooseServerSelectionError: connect ECONNREFUSED ::1:27017

Just installed mongodb cant connect to server on Ubuntu 22.04

I just completed an installation of mongodb in my computer and, after starting and enabling it I keep getting the same error:
MongoDB shell version v4.2.23
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2022-11-10T16:25:32.787+0100 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:353:17
#(connect):2:6
2022-11-10T16:25:32.788+0100 F - [main] exception: connect failed
2022-11-10T16:25:32.788+0100 E - [main] exiting with code 1
I uninstalled and installed multiple times and tried solutions that worked for other people in similar posts but I can not make it work.
I have a feeling it have something to do with the port it is looking for (27017) but I do not know how to check if that is the problem and, if so, how to fix it.
Thanks!
Here are a few things to consider:
Check if the MongoDB process is running (you can verify using ps, netstat (check listen port) command in the server.
See if your MongoDB service runs locally. That is because by default, the listen address of MongoDB is localhost/loopback.
Check if the firewall is running and you have allowed the port.
Verify if you are able to use telnet to command the port 27017 from the application server.

mongodb suddenly stopped working on production server

I have a server running node and mongoDB. Mongo is suddenly throwing errors, I managed to get it started upon rebooting the server but the error reappears upon trying to handle a request.
The error when I try to run mongo in a shell is:
MongoDB shell version v4.4.6
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
My mongod.conf has the correct data path and I also tried setting it manually using mongod --dbpath and can confirm that it is correct.
mongod --repair doesn't work either.
Any ideas?
Turns out the server was out of storage. Running df showed that there was no disk space left.
I ended up adding a volume and moving my database and files there.

Error [MongoError]: failed to connect to server [cluster0.4mocw.gcp.mongodb.net:27017] on first connect

i'm using mongodb atlas for database, and facing this issue in connectivity
it shows, server is running on port 3000
but then shows Error [MongoError]: failed to connect to server [cluster0.4mocw.gcp.mongodb.net:27017] on first connect
please guide me

MongoError: js:237:13 connect failed [localhost:27017]

I would like to install Mongodb on IntelliJ (already with Angular and Node.js). I installed MongoDB and changed my environment variables. I use Windows 10. When I try the command line : "mongo dbs show", I get this error :
MongoDB shell version v3.4.10 connecting to:
mongodb://127.0.0.1:27017/dbs 2017-11-20T16:59:43.003+0100 W NETWORK
[thread1] Failed to connect to 127.0.0.1:27017 after 5000ms
milliseconds, giving up. 2017-11-20T16:59:43.003+0100 E QUERY
[thread1] Error: couldn't connect to server 127.0.0.1:27017,
connection attempt failed : connect#src/mongo/shell/mongo.js:237:13
#(connect):1:6 exception: connect failed
In order to fix it, I tried the instructions of related posts, that is to say :
-Create a data directory in "MongoDB\Server\3.4\data"
-Change the directoy "mongod --dbpath=..."
-Change the allowed port to 27017 thank to "add --port 27017"
I did those operations but it doesn't solve the problem. Would you know how to fix it ? I thank you very much in advance !

Resources