Issue
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.
Solution
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/
Answered By - Irakli Tchedia Answer Checked By - Dawn Plyler (WPSolving Volunteer)