Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Pymongo to connect to MongoDB on AWS instance from Windows

An error is repeatedly being thrown at this line:

client = MongoClient('ec2-12-345-67-89.us-east-2.compute.amazonaws.com', 27017,
             ssl=True, ssl_keyfile='C:\\mongo.pem')

(Paths and instance name changed for obvious reasons)

The port (27017) for mongo is allowed inbound connections from my AWS security group. First, I allowed only my IP, now I'm allowing all via that port. I have tried preceding the connection string with "mongodb://" and removing the SSL arguments (I'm fairly certain I don't need it).

The error IntelliJ keeps throwing me is:

pymongo.errors.ConnectionFailure: [WinError 10061] No connection could be made because the target machine actively refused it

It works if I transport the script to the AWS instance and replace the DNS with 'localhost' and remove SSL parameters, but I need this to work remotely.

like image 369
Roman Federici Avatar asked Oct 31 '22 13:10

Roman Federici


1 Answers

Three ideas:

  1. Ensure "bind_ip" is set to "0.0.0.0" in your mongod.conf and restart mongod, as @ajduke suggests.

  2. Make sure mongod is running.

  3. Try to connect to the mongod from your client machine using the "mongo" shell to see if it gives you a more informative error.

like image 154
A. Jesse Jiryu Davis Avatar answered Nov 15 '22 05:11

A. Jesse Jiryu Davis