connect to MongoDB through ssh tunnel using python

Viewed 26

I'm new to python, I asked to connect a MongoDB through an ssh tunnel, and then insert data in MongoDB into oracle DB. I've already sent my public key to the DB team and they sent me the below information :

ssh arash@34.58.115.11

DB info : host: localhost port: 27017 db_name: mymongodb

I already tried ssh_pymongo and ssh_tunnel but they didn't succeed. I would be thankful if you could help me in this regard.

from ssh_pymongo import MongoSession
session = MongoSession('34.58.115.11',user='arash')
db = session.connection['mymongodb']
#mycols = db["properties"]
#li = mycols.find_one()
#print(li)
list(db.collection.find({}))

also ssh_tunnel:

from sshtunnel import SSHTunnelForwarder
server = SSHTunnelForwarder(
'alfa.8iq.dev',
ssh_username="arash",
remote_bind_address=('34.58.115.11'))
server.start()
0 Answers
Related