Using Pymongo to connect to MongoDB on AWS instance from Windows

淺唱寂寞╮ 提交于 2019-12-23 19:14:36

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/27277061/using-pymongo-to-connect-to-mongodb-on-aws-instance-from-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!