Unable to connect mongodb running on ec2 - mongodb

I am trying to connect with mongodb, But it is giving me error.
MongoDB shell version: 3.2.22 connecting to: test
2019-09-07T05:17:09.460+0000 W NETWORK [thread1] Failed to connect to
127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused 2019-09-07T05:17:09.461+0000 E QUERY
[thread1] Error: couldn't connect to server 127.0.0.1:27017,
connection attempt failed : connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
Tried:
sudo nano /etc/mongod.conf
Commenting bindip
#network interfaces
net:
port : 2701
#bindip = [0.0.0.0]
Setting up this to
#network interfaces
net:
port : 2701
bindip : 0.0.0.0
Setting up this to
#network interfaces
net:
port : 2701
bind_ip = 0.0.0.0
Setting up this to
#network interfaces
net:
port : 2701
bindip = [0.0.0.0]
Saved this file then :
sudo service mongod restart mongo
Again connection refused giving same error :
MongoDB shell version: 3.2.22 connecting to: test
2019-09-07T05:17:09.460+0000 W NETWORK [thread1] Failed to connect to
127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused 2019-09-07T05:17:09.461+0000 E QUERY
[thread1] Error: couldn't connect to server 127.0.0.1:27017,
connection attempt failed : connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
Any Help?

Just curious, Did you enable the AWS security group for that port since you are connecting remotely?
https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html#VPCSecurityGroups

try with below script :
mongod --fork --logpath /opt/app/mongo/mongod.log --auth --port 27017 --dbpath /var/lib/mongodb --bind_ip_all

Related

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27

I want to change the default port of mongodb so I did :
sudo nano /etc/mongod.conf
# network interfaces
net:
port: 27042
bindIp: 127.0.0.1
and
sudo service mongod start
But now when I want to run "mongo" I got this error:
MongoDB shell version v4.0.24
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2021-05-18T12:44:36.436+0200 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:356:17
#(connect):2:6
exception: connect failed
The message says " couldn't connect to server 127.0.0.1:27017" despite I changed the port in mongod.conf. I even tried to reboot my computer but it still not working.
UFW is not active si I don't think it's a firewall problem.
Based on your mongod.conf file, MongoDB will run on port 27042. When you run the command mongo without parameter --port, it will connect to the default port 27017 then you have the error.
I think this command mongo --port 27042 will work.

MongoDB, remote connection failing

I'm trying to connect to mongoDB server running in another AWS Account from my other AWS account to refresh the content.
I'm getting an error.
I NETWORK [thread1] Socket recv() errno:104 Connection reset by peer mongo_db_server:27017
I NETWORK [thread1] SocketException: remote: (NONE):0 error: 9001 socket exception [RECV_ERROR] server [mongodb_db_server:27017]
2021-01-14T23:26:26.015-0500 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host 'mongodb_db_server:27017' :
connect#src/mongo/shell/mongo.js:231:14
#(connect):1:6
Remote MongoDB server config has
net:
port: 27017
bindIp: 0.0.0.0
Security groups allow connection to 27017 from 0.0.0.0/0 fo testing purpose.
what am i missing?
It was due to network connectivity.

Mongo errno:111 Connection refused (ubuntu)?

my mongod service is unable to start i try all the solution available i tried following commands
sudo rm /var/lib/mongod/mongod.lock
sudo service mongod start
sudo service mongod restart
but still get the following error :-
MongoDB shell version: 3.2.19
connecting to: test
2018-07-23T04:49:02.322+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2018-07-23T04:49:02.322+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed

Why is it giving me active:failed error while installation of mongodb on my ubuntu 16.04 LTS?

MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017
2017-12-06T12:16:58.540+0530 W NETWORK [main] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-12-06T12:16:58.540+0530 E QUERY [main] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:234:13
#(connect):1:6
exception: connect failed
You need to first start mongo server at port 27017.
You can do it by executing following command:
mongod --port 27017 --dbpath [database_path]

Could not connect to mongodb. errno:111 Connection refused

I am using mongodb on ubuntu-16.04 but mongodb give server connection error:
MongoDB shell version: 3.2.9 connecting to: test
2016-09-23T12:01:10.258+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016-09-23T12:01:10.286+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed : connect#src/mongo/shell/mongo.js:229:14 #(connect):1:6 exception: connect failed
What can I do?
looks like your mongod process is not running on port 27017. Make sure your mongod process is running maybe verify with linux command.
If you start mongod process and even then it's failing to connect with mongo command, it means it's failing to intialize, check out designated mongo log file for the reason