Mongodb is not connecting with external ip address - mongodb

I want to host the mean stack application in windows server R12 , Application is accessible when i use Private IP address of the server but it is not accessible when I user the external Ip address or the domain name of the server.I tried with bindIp with addition of One more Ip address. It is not working.
It is showing an error as below
MongoDB shell version v4.0.1 connecting to:
mongodb://xxx.xxx.xx.xx:27017/ 2018-08-09T16:53:22.656+0530 E QUERY
[js] Error: couldn't connect to server xxx.xxx.xx.xx:27017, connection
attempt failed: SocketException: Error connecting to
xxx.xxx.xx.xx:27017 :: caused by :: No connection could be made
because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:257:13 #(connect):1:6 exception:
connect failed

mongod --repair worked for me ,
sudo mongod --repair
sudo mongod
Then open a different tab/terminal:
mongo
you can check this question here

Related

Not able to connect to mongodb running in VM (virtual Machine) from local system

I created an AWS EC2 (ubuntu-20.04) instance and setup a mongo server as per https://www.mongodb.com/docs/v4.4/tutorial/install-mongodb-on-ubuntu/
(mongo server is running in default port 27017 and not secured by any username/password)
I am able to connect to it from within the VM (after connecting to VM by SSH), by running the terminal command:
mongo
I have configured EC2 instance's Security Group's inbound rule to access port 27017 from my local system's IP.
however when I try to connect to it from my local system's terminal by command:
mongo --host "<public_ip_of_vm>:27017"
Its throwing error:
connecting to:
mongodb://<public_ip_of_vm>:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server <public_ip_of_vm>:27017, connection attempt
failed: SocketException: Error connecting to <public_ip_of_vm>:27017 :: caused
by :: Connection refused : connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6 exception: connect failed exiting with code 1
Not sure what's causing this issue, I have checked the ufw rules too.
port 27017 is open.
Did you modify ?
/etc/mongod.conf
Have a look at this tutorial, especially the step 2. Maybe this helps
https://ianlondon.github.io/blog/mongodb-auth/
Connection refused means you probably do not have a firewall problem. Connection timeout indicates a firewall issue.
Since you can connect locally via localhost, the error indicates that the mongo process is only listening on localhost.
Edit the file /etc/mogod.conf. The interesting line is bindIp.
It should look like this for IPv4 only:
bindIp: 0.0.0.0
If you have IPv6 enabled
bindIp: ::,0.0.0.0
Warning: enable authentication first. You might be hacked faster than you might expect.

error mongo without mongod running first locally in win 10

I have this mongo.zip installed in my win 10.
I have set the environment path with bin.
Somehow whenever I start command line,
my mongo cannot start without mongod first.
C:\Users\asus>mongo
MongoDB shell version v4.4.1
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 :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
but if I run mongod before mongo, mongo is running perfectly.
So, my question is: how do I running mongo without mongod locally.
PS. my compass is running and can connect to AWS cloud.
Please provide pictures if you can.
Thank you!
I think you, first of all, you have to know about the difference between them.
Mongod is the process of MongoDB.
Mongo is a shell. You can use it to connect and run any mongo command on any MongoDB.
So, your error means;
You are trying to connect your own MongoDB with typed mongo, because the default -host parameter is localhost. But your mongod process is not running. So you have to start it.
connecting to: mongodb://127.0.0.1:27017
127.0.0.1:27017 equals localhost.
If you have MongoDB (mongod process) on AWS. You should connect with below command
mongo --host mongodb0.example.com:28015

Unable to connect to MongoDB on EC2

Unable to connect MongoDB (Version 4.0.5) on EC2 (Windows Server 2018)
I have tried all the options.
1) Modify mongod.cfg with
net:
port: 27017
bindIp: 0.0.0.0
bindIpAll: true
2) start with mongod --bind_all_ip
3) My security group on EC2 has allowed 27017 port inbound for 0.0.0.0/0.
I'm trying to connect through terminal
mongo mongodb://*********.compute.amazonaws.com:27017
However, I get following exception when connecting through mongo shell
mongodb://e*******.compute.amazonaws.com:27017/?
gssapiServiceName=mongodb
2019-01-21T15:51:11.044-0800 E QUERY [js] Error: couldn't connect
to server *****.compute.amazonaws.com:27017, connection attempt
failed: SocketException: Error connecting to
******.compute.amazonaws.com:27017 (54.244.203.203:27017) :: caused by
:: Operation timed out :
connect#src/mongo/shell/mongo.js:328:13
#(connect):1:6
exception: connect failed
What else I need to do?
Also, it seems my mongodb.cfg has no effect on the server. When I start server with above change in cfg file, I get the warning in server console that the server is bound to localhost, regardless. Starting the server with mongod --bind_all_ip gets rid of that warning.
Firewall was the problem. Need to open port 27017 by running WF.msc from run command on Windows. Spent a whole day trying to figuring out all other options. I still don't know how to get the mongod.cfg working for all ip addresses. I need to run mongod with --bind_all_ip option for that.

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.