Connect to a MongoDB over ssh.
from databaseConnection import DatabaseConnection, DatabaseConfigurator
dbcontext = DatabaseConnection(DatabaseConfigurator('config.ini').Config())
db = dbcontext.connect()
# Or: db = dbcontext.connect('another-database-name')
mycollection = 'some-name'
db.[mycollection].find_one({})
# Or just like this if the collection-name allows it:
db.some_name.find_one({})The connection needs the following configuration values:
REMOTE_HOSTREMOTE_BIND_ADDRESSREMOTE_BIND_PORTSSH_USERSSH_PASSMONGO_DB(optional, but must then be passed in as an argument todbcontext.connect())MONGO_USER(optional, only needed if authorization is enabled)MONGO_PASS(optional, only needed if authorization is enabled)
These can be stored in the default databaseConnectionConfig.ini-file, or in another config-file which can be passed in. Another option would be to omit the configuration file entirely and instead send in an object to the DatabaseConfig.CustomConfigSource().
pip install -r requirements/base.txt