I have a web app written in Django with mongoengine in a Digital Ocean droplet. During the developing step I used a sample of the main database that is located in a remote enviroment. But now I want to connect the Django web app to the main MongoDB database. How can I do this? With an ssh tunnel (I already use it between both environments)? If so, how do I do such connection? I know how to establish an ssh tunnel with pymongo:
from sshtunnel import SSHTunnelForwarder
import pymongo
server = SSHTunnelForwarder(
(remote_ip_address, 22),
ssh_private_key="/home/username/.ssh/id_rsa",
ssh_username="username",
remote_bind_address=('127.0.0.1', 27017),
)
server.start()
client = pymongo.MongoClient('127.0.0.1', server.local_bind_port)
But how do I do the equivalent connection with the Django web app? At the present moment I have the following definitions in the settings.py
file.
# MongoDB settings
MONGODB_DATABASES = {'default': {'name':'dbname'} }
DATABASES = {'default': {'ENGINE': 'django.db.backends.dummy'} }