pymongo - Unable to connect to mongodb running on EC2

不打扰是莪最后的温柔 提交于 2019-12-08 14:27:36

EC2 will close 27017 port by default. Create the in-bound rule as described here and here.

I tried all the options and finally this worked.

client = MongoClient("mongodb://" + ssh_address+":27017") # No private key passing 
auth = client.myDB.authenticate(mongo_username,mongo_password) # Authenticate to myDB and not admin
db = client.myDB

So basically I don't need to pass a private key (which is required when doing ssh over to the EC2) since the port was already opened for all incoming IPs ( I guess this was an important fact that I should have known and posted in the question).

Also I was trying to authenticate via the admin DB, which I shouldn't have done because I was given access to myDB only.

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