使用Pymongo从Windows连接到AWS实例上的MongoDB [英] Using Pymongo to connect to MongoDB on AWS instance from Windows
问题描述
此行反复抛出错误:
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)
允许mongo的端口(27017)来自我的AWS安全组的入站连接.首先,我只允许我的IP,现在允许所有通过该端口的IP.我试过在连接字符串前面加上"mongodb://"并删除SSL参数(我很确定我不需要它).
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).
IntelliJ不断抛出的错误是:
The error IntelliJ keeps throwing me is:
pymongo.errors.ConnectionFailure: [WinError 10061] No connection could be made because the target machine actively refused it
如果我将脚本传输到AWS实例并用'localhost'替换DNS并删除SSL参数,则可以正常工作,但是我需要它来远程工作.
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.
推荐答案
三个想法:
-
确保在mongod.conf中将"bind_ip"设置为"0.0.0.0",然后按照@ajduke的建议重新启动mongod.
Ensure "bind_ip" is set to "0.0.0.0" in your mongod.conf and restart mongod, as @ajduke suggests.
确保mongod正在运行.
Make sure mongod is running.
尝试使用"mongo" shell从客户端计算机连接到mongod,以查看它是否为您提供了更多有用的错误.
Try to connect to the mongod from your client machine using the "mongo" shell to see if it gives you a more informative error.
这篇关于使用Pymongo从Windows连接到AWS实例上的MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!