Amazon EC2 unable to connect to MongoDB via client mongo shell - mongodb

I am unable to connect to remote MongoDB from my local Machine. Getting the below exceptions while trying to connect using Mongo shell.
Request from shell:
mongo --username[username] --password[password]--host [Public DNS] --port 27017
Response:
Failed to connect to :27017, reason: errno:61 Connection refused
2015-12-03T16:31:51.514-0500 E QUERY Error: couldn't connect to server , connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
I have followed the below template to configure the server on the Amazon cloud.
https://s3.amazonaws.com/quickstart-reference/mongodb/latest/doc/MongoDB_on_the_AWS_Cloud.pdf
Can anyone help me to resolve this issue.
Thank you in advance.

Related

Could not run MongoDB server in Ubuntu system

I am trying to run MongoDB in my Ubuntu machine using the following command but I am getting some error.
Command:
mongo
Error:
connecting to: mongodb://127.0.0.1:27017<br>
2019-12-23T17:00:38.815+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused<br>
2019-12-23T17:00:38.818+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :<br>
connect#src/mongo/shell/mongo.js:251:13<br>
#(connect):1:6<br>
exception: connect failed
How can I resolve this issue and run MongoDB successfully?
Normally this is caused because you didn't start mongodb service before you try starting mongo shell. You can check for a system service status. If it is failing because of some error try to fix it and start the process. Below are few things that might help with it.
Check if mongodb service is up and running
sudo systemctl status mongodb
If not start mongodb service on your ubuntu machine
sudo systemctl start mongodb
Start mongo shell
mongo

Could not connect to mongodb server

I have mongodb server. When I try to connect to it with mongoclient from first machine I cannot connect to server but at the same time when I try to connect to mongodb server from second machine I can access database successfully.
I am getting following error from first machine
QUERY [thread1] Error: couldn't connect to server xxxxxxx:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:240:13
#(connect):1:6
exception: connect failed
I am having verson 3.6 of mongodb on all the server's.
Delete this file and then launch mongo service: /tmp/mongodb-27017.sock

sailsJs mongodb connection error in docker container

Unable to connect sailsJs dockerimage to mongodb.
I am having issue while connecting mongodb running on local machine, not as mongo image.
mongodb is running on localhost:27017
error: Error: Failed to connect to MongoDB. Are you sure your configured Mongo instance is running?
Error details: {
Error: connect ECONNREFUSED 127.0 .0 .1: 27017
at Object.exports._errnoException(util.js: 1020: 11)
at exports._exceptionWithHostPort(util.js: 1043: 20)
at TCPConnectWrap.afterConnect[as oncomplete](net.js: 1090: 14)
name: 'MongoError',
message: 'connect ECONNREFUSED 127.0.0.1:27017'
}
If the container is running in a docker engine in the same host where your MongoDB server is running, you should try to run your docker container using --net=host if you want your container to be able to reach 127.0.0.1/localhost in the same host. I nice answer can be found here.
If you're using docker engine in a VM you may have to change the localhost IP for the public/private IP assigned to your mongodb server host.

mongo - couldn't connect to 127.0.0.1 - ip changed

I installed mongoDB and changed the IP to 10.3.Y.XX.
When i want to start mongo from terminal (> mongo), this error occurs:
Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1),
connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
Any idea how to solve this?
If you want to connect to something other than the default host (which is "localhost"), you need to tell your Mongo client application about it.
For example, on the command line you can do
mongo --host 10.3.x.y db_name

set up Apache2 virtual hosts and now MongoDB connection refused

I'm running Ubuntu 14.04 on an AWS EC2 instance with Apache2. This morning I upgraded my Apache2 settings to allow multiple virtual servers following these instructions: https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
Just now I tried to access my MongoDB instance, but I cannot do it either through the PHP MongoDB driver or through the shell. I get this error when attempting to connect with a PHP MongoClient():
Failed to connect to: localhost:27017: Connection refused'
and I get this error when trying to run the mongo shell:
2015-06-03T19:23:57.307+0000 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-06-03T19:23:57.308+0000 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
Everything was running fine just last night, and I haven't directly modified MongoDB settings. What can I do to fix this? How do Apache2 settings relate to MongoDB? I've been trying to look through the MongoDB docs, but I don't see anything that looks relevant.
You need to setup Security Group for your EC2 instance. And allow Inbound connection for the mongodb port, in your case 27017.
When I went through the logs, I saw a message that there was insufficient room for "journal file." I rebooted my AMI on an EC2 instance with more storage and reinstalled Mongo. That did the trick. I had uploaded a few files to the instance after updating my Apache2 settings, so those few more files must have pushed the instance past what Mongo could tolerate. Too bad the error message wasn't more helpful, but I should have checked the logs sooner. It would also be nice if the logs had a more explicit message.