1

I am trying to use pymongo to connect to a mongo database.

I have been given: DB_name DB_username DB_password DB_port SSH_address SSH_username mongo RSA private key (.pem file)

I have tried running

from pymongo import MongoClient

client = MongoClient(host=SSH_address,
                     port=DB_port,
                     username=DB_username,
                     password=DB_password)

client.list_database_names()

but get a timed out error.

How can I pass the remaining information (such as the RSA private key) to MongoClient, so that I can successfully connect?

EuRBamarth
  • 904
  • 1
  • 11
  • 27

1 Answers1

1

Using SSH tunnel client to connect the MongoDB client works for me:

server = SSHTunnelForwarder(
    (MONGO_HOST, MONGO_PORT),
    ssh_username=MONGO_USER,
    ssh_password=MONGO_PASS,
    remote_bind_address=('127.0.0.1', 27017)
)
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Taha Hamedani
  • 105
  • 1
  • 11