Skip to content

Instantly share code, notes, and snippets.

@lgarvey
Last active August 29, 2015 14:04
Show Gist options
  • Save lgarvey/9f127297e742d0bada48 to your computer and use it in GitHub Desktop.
Save lgarvey/9f127297e742d0bada48 to your computer and use it in GitHub Desktop.
#
# Connecting to MonogHQ via heroku with flask and mongoengine
#
# heroku/mongohq exposes the mongodb connection uri in the os.envion['MONGOHQ_URL']
#
# config.py
import os
MONGO_URI = os.environ.get('MONGOHQ_URL', None)
# ...
MONGODB_SETTINGS = {}
# MongoDB Config
if not MONGO_URI:
# local config:
MONGODB_SETTINGS['db'] = 'localdev'
MONGODB_SETTINGS['host'] = 'localhost'
MONGODB_SETTINGS['port'] = 27017
else:
# heroku:
# mongoengine.connect() accepts a host uri parameter, but also requires
# a db parameter. So grab it from the end of the host uri.
MONGODB_SETTINGS['db'] = MONGO_URI.split("/")[-1]
MONGODB_SETTINGS['host'] = MONGO_URI
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment